0
我有这样的代码在.htaccess:Apache的子域名重定向到文件夹,保存参数
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
...
(通配符subdmains规则已经到位,工作)
如果我浏览到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/测试/寄存器
我在这里做错了什么?提前致谢!
谢谢。我添加了L标志,即使我没有注意到使用上的任何重大差异,我想它会更好。我是新来的,那些RewriteCond应该在哪里? – rtrudel
RewriteConds应该在它们适用的规则之前。因为它们只适用于第一条规则,并且似乎是不必要的。通常情况下,您会在一般捕捉将请求转发给脚本的所有规则之前看到这些条件。 – matthew