我想执行这些重定向:
example.com/a/b/c ===> example.com/index.php?p=a/b/c
example.com/d/e/f ===> example.com/index.php?p=d/e/f
example.com/area2/b/c ===> example.com/index_area2.php?p=b/c
example.com/area2/d/e ===> example.com/index_area2.php?p=d/e
这就是我现在所拥有的:
RewriteRule ^area2(.*)$ /index_area2.php?p=$1 [L,QSA]
RewriteRule ^(.*)$ /index.php?p=$1 [L,QSA]
我收到内部服务器错误。这有什么不对? 每条规则都是独立的。
答案 0 :(得分:0)
您收到500错误,因为您的规则导致任何RewriteCond
无限循环。这样做:
RewriteEngine On
RewriteBase /
# If the request is for a valid directory
RewriteCond %{REQUEST_FILENAME} -d [OR]
# If the request is for a valid file
RewriteCond %{REQUEST_FILENAME} -f
# skip them from rules below
RewriteRule ^ - [L]
RewriteRule ^area2/(.+)$ index_area2.php?p=$1 [L,QSA,NC]
RewriteRule ^(.+)$ index.php?p=$1 [L,QSA]