我在.htaccess中有这段代码:
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !\.(css|gif|ico|jpg|js|png|swf|txt)$
# If empty subdomain, replace with "www"
RewriteCond %{HTTP_HOST} ^example.com$
RewriteRule ^(.*) http://www.example.com/$1 [QSA,L,R=301]
# If subdomain isn't empty and not "www", redirect to "folder"
RewriteCond %{HTTP_HOST} !^www\.example\.com
RewriteCond %{HTTP_HOST} ^(.*)\.example\.com$
RewriteRule (.*) http://www.example.com/%1/$1 [QSA,R=301]
#PAGES REDIRECTION
RewriteRule ^(.*)/register/ /index.php?sub=$1&page=register
RewriteRule ^(.*)/register /index.php?sub=$1&page=register
RewriteRule ^(.*)/lostpass/ /index.php?sub=$1&page=lostpass
RewriteRule ^(.*)/lostpass /index.php?sub=$1&page=lostpass
...
(通配符子域的规则已经到位并正常工作)
如果我浏览 http://test.example.com ,则会将其正确重定向到 http://www.example.com/test 但是当我尝试浏览 http://test.example.com/register 时,它实际上会重定向到 http://www.example.com/test/index.php ?sub = http://www.example.com/test& page = register ,应该重定向到 http://www.example.com/test/register
我在这里做错了什么?提前谢谢!
答案 0 :(得分:0)
尝试将L
标记添加到您的第二个重定向规则中,类似于第一个重定向规则中的标记。
RewriteRule (.*) http://www.example.com/%1/$1 [QSA,R=301,L]
您的重写URI似乎是passing through to the next rule。
另外,我不认为您的前两个RewriteCond
位于正确的位置。