Forum Moderators: phranque

Message Too Old, No Replies

Trouble setting up a redirect

         

smithaa02

1:44 pm on May 17, 2007 (gmt 0)

10+ Year Member



Say there is site1.com and it has an alias of site2.com. For SEO reasons, I want a .htaccess file to check to see if the domain name site2.com is being used and if so, I was hoping to have it redirect to site1.com.

I added the following line in my .htaccess file, but it did not work:

RedirectMatch 301 (.*)site2.com [site1.com...]

Is this because the first parameter has to be a file or subdirectory and can't be a domain? If so, how would I setup a conditional redirect based on the contents of the domain name?

jdMorgan

3:32 pm on May 17, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The Redirect directives in mod_alias don't have the ability to check the host name. You can use mod_rewrite to do this. Example:

# Enable mod_rewrite
Options +FollowSymLinks
RewriteEngine on
#
# Redirect site2.com, www.site2.com, and site1.com to www.site1.com
RewriteCond %{HTTP_HOST} ^(www\.)?site2\.com [OR]
RewriteCond %{HTTP_HOST} ^site1\.com
RewriteRule (.*) http://www.site1.com/$1 [R=301,L]

Jim