在向htaccess添加行后,URL重写失败

时间:2014-10-17 13:51:36

标签: apache .htaccess mod-rewrite redirect rewrite

我的.htaccess遇到了一个小问题,我似乎无法修复它。

RewriteEngine on
# force ssl

RewriteCond %{REQUEST_URI} !^/?(apps|user)/ 
RewriteRule ^5/(.*)/(.*).html$ /~ond/index.php?id=5&page=$1&titel=$2
RewriteRule ^(.*)/(.*).html$ /~ond/index.php?id=$1&titel=$2

以上示例可以通过以下网址完美运行:www.domain.com/123/title.html 不过,我想添加其他规则:RewriteRule ^(.*)$ /~ond/index.php?id=$1 [L]

当我在htaccess底部添加代码段时,它将返回内部服务器错误500.使用过的网址:www.domain.com/This_Is_a_Test

我做错了什么?这应该是一个非常小的问题。

感谢。

1 个答案:

答案 0 :(得分:0)

由于无限循环导致500服务器错误。通过保持RewriteCond仅允许非文件,非目录请求来阻止它:

RewriteEngine on

RewriteCond %{REQUEST_URI} !^/?(apps|user)/ 
RewriteRule ^5/(.*)/(.*).html$ /~ond/index.php?id=5&page=$1&titel=$2 [L,QSA]

RewriteRule ^(.*)/(.*).html$ /~ond/index.php?id=$1&titel=$2 [L,QSA]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /~ond/index.php?id=$1 [L,QSA]