我需要将子域上的特定urlredirect到不同子网域上的完全不同的url。 例如:
http://foo.example.com/this-is-my-page
需要301
来:
http://bar.example.com/this-is-really-my-page
我已经尝试在.htaccess
设置一个简单的Redirect 301
,但它似乎并没有工作。 例如:
Redirect 301 http://foo.example.com/this-is-my-page http://bar.example.com/this-is-really-my-page
尝试这个:
RewriteEngine On RewriteCond %{HTTP_HOST} ^sub\.domain\.com$ [NC] RewriteRule ^(.*) http://newsub.domain.com/ [L,R]
它在我身边工作
这就是我最终做的事情:
# first re-write all foo.example.com requests to bar.example.com RewriteCond %{HTTP_HOST} ^foo\.example\.com [NC] RewriteRule (.*) http://bar.example.com/$1 [L,R=301] # now re-write each individual URL RewriteRule ^this-is-mypage /this-is-really-my-page [NC,L,R=301]
如果你想要这样的东西:
http://foo.example.com/this-is-my-page
至
http://bar.example.com/this-is-really-my-page
但是http://foo.example.com/mypage
不得不作出响应而没有重定向
这是可能的 ??
因为:
# first re-write all foo.example.com requests to bar.example.com RewriteCond %{HTTP_HOST} ^foo\.example\.com [NC] RewriteRule (.*) http://bar.example.com/$1 [L,R=301] # now re-write each individual URL RewriteRule ^this-is-mypage /this-is-really-my-page [NC,L,R=301]
将无法正常工作