Reputation: 1771
I need to redirect particular URLs on a subdomain to completely different URLs on a different subdomain. For example:
http://foo.example.com/this-is-my-page
Needs to 301
to:
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:
Redirect 301 http://foo.example.com/this-is-my-page http://bar.example.com/this-is-really-my-page
Upvotes: 6
Views: 21727
Reputation: 312
try this:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^sub\.domain\.com$ [NC]
RewriteRule ^(.*) http://newsub.domain.com/ [L,R]
it works on my side
Upvotes: 3
Reputation: 1771
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]
Upvotes: 2