Apache将子域重定向到文件夹,保留参数
我在.htaccess中有此代码:Apache将子域重定向到文件夹,保留参数,apache,.htaccess,mod-rewrite,wildcard-subdomain,url-redirection,Apache,.htaccess,Mod Rewrite,Wildcard Subdomain,Url Redirection,我在.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 ^(.*) h
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
我做错了什么?提前谢谢 尝试将
L
标志添加到第二个重定向规则中,类似于第一个重定向规则中的设置方式
RewriteRule (.*) http://www.example.com/%1/$1 [QSA,R=301,L]
看起来您重写的URI是
另外,我认为前两个
RewriteCond
的位置不正确 谢谢。我添加了L标志,我想它会更好地工作,即使我没有注意到在使用上有任何显著的差异。我是新手,重写条件应该在哪里?重写条件应该在它们应用的规则之前。事实上,它们只适用于第一条规则,似乎没有必要。通常,在将请求转发到脚本的常规“捕获所有”规则之前,您会看到这些条件。