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)
有什么想法吗?
答案 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]