htaccess在第二个RewriteRule上抛出错误

时间:2014-05-09 14:43:12

标签: apache .htaccess mod-rewrite

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([a-zA-Z]+)/([0-9a-zA-Z-_]+)/? /pages/index.php?page_url=$2&lang=$1 [QSA,L]
RewriteRule ^([a-zA-Z]+)/? /pages/index.php?page_url=home&lang=$1 [QSA,L]

这两个规则都可以自行运行,但如果我有这两个规则,我会收到500内部服务器错误。

我要做的是site.com/en/site.com/pages/index.php?page_url=home&lang=$1(在这种情况下是en)

但在site.com/en/home/上转到site.com/pages/index.php?page_url=$2&lang=$1(在本案中分别为home和en)

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

由于错误的正则表达式导致规则循环,因此出现500错误。

保持这样的规则:

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([a-zA-Z]+)/([\w-]+)/?$ /pages/index.php?page_url=$2&lang=$1 [QSA,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([a-zA-Z]+)/?$ /pages/index.php?page_url=home&lang=$1 [QSA,L]