htaccess重写子域并请求uri

在我的htaccess中遇到了重写条件的问题。 我需要redirect来自子域的请求。 但是,每种语言都有三个子域:en.foo.com,es.foo.com,www.foo.com。 如果他们有请求,他们必须坚持相应的子域名。

例如:

要求:
fdsfds.foo.com/test

期望: www.foo.com/test

目前: www.foo.com

.htaccess文件:

# BEGIN .net to .com redirect RewriteEngine On RewriteCond %{HTTP_HOST} foo.net$ [NC] RewriteRule ^(.*)$ http://www.foo.com/$1 [R=301,L] # END .net to .com redirect # BEGIN force www on non-www requests RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$ RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L] # END force www on non-www requests # BEGIN .net to .com redirect (english) RewriteCond %{HTTP_HOST} ^en\.foo\.net$ [NC] RewriteRule ^(.*)$ http://en.foo.com/$1 [R=301,L] # END .net to .com redirect (english) # BEGIN .net to .com redirect (spanish) RewriteCond %{HTTP_HOST} ^es\.foo\.net$ [NC] RewriteRule ^(.*)$ http://es.foo.com/$1 [R=301,L] # END .net to .com redirect (spanish) # BEGIN .net to .com redirect (spanish) RewriteCond %{HTTP_HOST} ^www\.foo\.net$ [NC] RewriteRule ^(.*)$ http://www.foo.com/$1 [R=301,L] # END .net to .com redirect (spanish) # To redirect all users to access the site WITH the 'www.' prefix, # (http://example.com/... will be redirected to http://www.example.com/...) # uncomment the following: RewriteCond %{HTTP_HOST} !^www\. [NC] RewriteCond %{HTTP_HOST} !^es\. [NC] RewriteCond %{HTTP_HOST} !^en\. [NC] RewriteRule ^ http://www.foo.com/ [L,R=301] 

那么,我想你只需要修改最后一个RewriteRule,它将每个其他请求(即不是以es或en或www开头的请求)redirect到http://www.foo.com/ 。 你可以尝试这样的事情:

 RewriteRule ^(.*)$ http://www.foo.com/$1 [L,R=301] 

请让我知道它是否正确。