apache - 尝试调试 .htaccess 文件
问题描述
我开始使用我的 PHP 网页的 mod_rewrite 函数
我非常兴奋地创建了我的第一个重写规则,但是当我添加到我的 .htaccess 文件时,所有网页都出现错误 500(不仅是我试图重定向的那个)。
这是我的文件:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^([^/]*)/(([^/]*)/)*$
RewriteCond %{REQUEST_FILENAME}index.php !-f
RewriteCond %{REQUEST_FILENAME}index.html !-f
RewriteCond %{REQUEST_FILENAME}index.htm !-f
RewriteRule ^/([a-zA-Z\-]+)\/([a-zA-Z\-]+)\/([0-9]+)$ ficha_jugador.php?idjugador=$3 [L]
RewriteRule (.*) /index.html [L]
我的新行是第 8 行,其余的默认在我的网络服务器中
我为第 8 行尝试了一些更简单的方法来测试
RewriteRule ^writetest\.html http://www.after5pc.net [QSA,L]
但它也以 500 错误结束,所以它似乎不是语法问题
最终,我想做的是改变(塞住我的网址)
http://cadistas1910.com/ficha_jugador.php?idjugador=1304
by
http://cadistas1910.com/alvaro-garcia-canto/alvaro-garcia/1304
大家可以提供什么帮助吗?非常感谢!
解决方案
I believe last line of your .htaccess file could be the culprit, could you please try following once.
RewriteEngine On
RewriteBase /
RewriteRule ^([a-zA-Z\-]+)\/([a-zA-Z\-]+)\/([0-9]+)$ ficha_jugador.php?idjugador=$3 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.html [L]
I have added a condition there to rewrite to index.html if and only if Uri has non existing directory/file, why because it will create an infinite loop without a condition, since you are rewriting everything to index.html and everything(by regex) matched index.html also, hence loop and 500 internal error you are getting.
Also your rule to rewrite from http://localhost:80/alvaro-garcia-canto/alvaro-garcia/1304
TO http://localhost:80/ficha_jugador.php?idjugador=1304
have been changed into a single line above.
NOTE: To fix this either make your links absolute or use base tag. In the header of your webpage add this <base href="/">
so that your relative links can load from the correct location.
推荐阅读
- python - 检查网页python中的所有新数字
- java - 我在 Java 中的 replaceAll() 中的正则表达式不起作用
- mongodb - Loopback hasMany 关系没有返回数据
- c# - 组合框特定项目 c#
- javascript - 两个有冲突的拖放库
- amazon-web-services - 使用 S3 进行 Codedeploy 总是在 5 分钟后失败
- java - 静态常量是否违反“封装”?
- reactjs - 如何使用打字稿制作一个复制 useState()[1] 的函数?
- python - 除非我物理移动鼠标,否则鼠标不会记录移动
- c# - 在 web.config 中为 Web 服务配置超时