0
votes

Not sure how to pull this off. Say I have example.com and example2.com. I want all requests from example2.com to 301 redirect to example.com. That part isn't hard.

RewriteCond %{HTTP_HOST} ^example2.com [NC,OR]
RewriteCond %{HTTP_HOST} ^www.example2.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301,NC]

What I would like to do though when someone enters www.example2.com is to have them redirected to www.example.com/a-special-page.html and have everything else redirect exactly as entered. ie www.example2.com/another-page.html redirects to www.example.com/another-page.html

1

1 Answers

0
votes

Have specific redirect first and then the generic redirect like this:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^(www\.)?example2\.com$ [NC]
RewriteRule ^/?$ http://www.example.com/a-special-page.html [L,R=301]

RewriteCond %{HTTP_HOST} ^(www\.)?example2\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]

Make sure to test it after clearing your browser cache.