How can I redirect specific subdomain URLs using .htaccess?

I need to redirect specific URLs on a subdomain to completely different URLs in another subdomain. For instance:

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

Required 301to:

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

Ive tried setting simple Redirect 301in .htaccess, but it doesn't seem to work. For instance:

Redirect 301 http://foo.example.com/this-is-my-page http://bar.example.com/this-is-really-my-page
+5
source share
3 answers

try the following:

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

he works by my side

+3
source

Here is 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]
+2
source

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/mypagemust respond without redirection

Is it possible?

Let's pretend 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]

does not work

0
source

All Articles