如何使用.htaccess 301重定向特定的子域名网址?

时间:2021-08-03 10:51:58

I need to redirect particular URLs on a subdomain to completely different URLs on a different subdomain. For example:

我需要将子域上的特定URL重定向到不同子域上完全不同的URL。例如:

http://foo.example.com/this-is-my-page

Needs to 301 to:

需要到301:

http://bar.example.com/this-is-really-my-page

I’ve tried setting up a simple Redirect 301 in .htaccess but it doesn't seem to work. For example:

我已经尝试在.htaccess中设置一个简单的Redirect 301,但它似乎不起作用。例如:

Redirect 301 http://foo.example.com/this-is-my-page http://bar.example.com/this-is-really-my-page

3 个解决方案

#1


3  

try this:

尝试这个:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^sub\.domain\.com$ [NC]
RewriteRule ^(.*) http://newsub.domain.com/ [L,R]

it works on my side

它适用于我

#2


2  

Here's what I ended up doing:

这是我最终做的事情:

# 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]

#3


0  

if you want something like this :

如果你想要这样的东西:

http://foo.example.com/this-is-my-page 

to

http://bar.example.com/this-is-really-my-page

but http://foo.example.com/mypage have to respond with no redirect

但是http://foo.example.com/mypage必须回复没有重定向

It's possible ??

这是可能的 ??

Beacause that :

因为:

# 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]

will not working

不行

#1


3  

try this:

尝试这个:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^sub\.domain\.com$ [NC]
RewriteRule ^(.*) http://newsub.domain.com/ [L,R]

it works on my side

它适用于我

#2


2  

Here's what I ended up doing:

这是我最终做的事情:

# 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]

#3


0  

if you want something like this :

如果你想要这样的东西:

http://foo.example.com/this-is-my-page 

to

http://bar.example.com/this-is-really-my-page

but http://foo.example.com/mypage have to respond with no redirect

但是http://foo.example.com/mypage必须回复没有重定向

It's possible ??

这是可能的 ??

Beacause that :

因为:

# 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]

will not working

不行