Htaccess 301 Redirection

I'm trying to redirect 301

http://www.domain.com/page.html

to

http://subdomain.domain.com/page.html

and tried:

redirect 301 /page.html http://subdomain.domain.com/page.html

The problem is that both the domain and subdomain are pointing to the same directory, and this makes the redirection in a way that will never be completed.

also tried without success:

RewriteCond %{HTTP_HOST} ^domain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.domain.com$
RewriteRule ^page\.html$ "http\:\/\/subdomain\.domain\.com\/page\.html" [R=301,L]
+3
source share
1 answer

ok ... I realized this - the second case works - you just need to put it right after RewriteEngine On:

RewriteCond %{HTTP_HOST} ^domain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.domain.com$

RewriteRule ^page.html$ http://subdomain.domain.com/page.html [R=301,L]

and this can be used for several rules under one condition:

RewriteCond %{HTTP_HOST} !^(www\.)?domain.com$ [NC]
RewriteRule .* - [S=2]

RewriteRule ^page.html$ http://subdomain.domain.com/page.html [R=301,L]
RewriteRule ^page-2.html$ http://subdomain.domain.com/page-2.html [R=301,L]
+1
source

All Articles