Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache将子域重定向到文件夹,保留参数_Apache_.htaccess_Mod Rewrite_Wildcard Subdomain_Url Redirection - Fatal编程技术网

Apache将子域重定向到文件夹,保留参数

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

我在.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


我做错了什么?提前谢谢

尝试将
L
标志添加到第二个重定向规则中,类似于第一个重定向规则中的设置方式

RewriteRule (.*) http://www.example.com/%1/$1 [QSA,R=301,L]
看起来您重写的URI是


另外,我认为前两个
RewriteCond
的位置不正确

谢谢。我添加了L标志,我想它会更好地工作,即使我没有注意到在使用上有任何显著的差异。我是新手,重写条件应该在哪里?重写条件应该在它们应用的规则之前。事实上,它们只适用于第一条规则,似乎没有必要。通常,在将请求转发到脚本的常规“捕获所有”规则之前,您会看到这些条件。