0
votes

We have 2 subdomains www.mydomain.com and www2.mydomain.com. I'm trying to redirect pages to new site as below:

  • www.mydomain.com/support to newdomain.com/site1/page1.html
  • www2.mydomain.com/support to newdomain.com/site2/page2.html

I've set the redirect rule in httpd.conf as below:

RewriteCond %{HTTP_HOST} (www.)?mydomain.com

RewriteCond %{HTTP_HOST} !^$

RewriteRule ^/support/?$ http://newdomain.com/site1/page1.html [R=301,NC,L]

RewriteCond %{HTTP_HOST} (www2.)?mydomain.com

RewriteCond %{HTTP_HOST} !^$

RewriteRule ^/support/?$ http://newdomain.com/site2/page2.html [R=301,NC,L]

The first redirect rule is working fine, but not the other. In above case, both www and www2.mydomain.com/support are going to newdomain.com/site1/page1.html

Any help is appreciated!

2

2 Answers

0
votes

You can try this, anti-slashed point is a true point match, I've tested in apache2:

RewriteEngine on
RewriteCond %{HTTP_HOST} www\.mydomain.com
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^/support/?$ http://mydomain.com/site1/page1.html [R=301,NC,L]

RewriteCond %{HTTP_HOST} www2\.mydomain.com
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^/support/?$ http://mydomain.com/site2/page2.html [R=301,NC,L]

We use www. instead of (www.)?.

0
votes

try to check boths www and www2 in the same condition

RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.example.com|www2\.example.com [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^/support/?$ http://example.com/site1/page1.html [R=301,NC,L]