Forum Moderators: phranque

Message Too Old, No Replies

         

rjames

6:00 pm on Jun 17, 2005 (gmt 0)

10+ Year Member



Hello everyone,

I want to permanently redirect any traffic going to a bunch of domains I have to one single domain. Example:

Anyone going to:

domain.com
www.domain.net
domain.net
www.domain.org
domain.org

Redirect to:

www.domain.com

I read somewhere that this can be acomplished by inserting a script like this into the .htaccess file:


RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain.com
RewriteRule (.*) http://www.domain.com/$1 [R=301,L]

How can I perform multiple conditions as described above?

jonrichd

12:43 pm on Jun 21, 2005 (gmt 0)

10+ Year Member



Assuming that you want all incoming requests to your site to be redirected to www.domain.com, use this line in your .htaccess:

RewriteCond %{HTTP_HOST}!^www\.domain\.com
replacing
RewriteCond %{HTTP_HOST} ^domain.com

In the example you provided, you were looking for requests for domain.com (without the www), and then processing the rule.

In the modification I am suggesting, you are looking for requests for anything but www.domain.com (the! character means not), and then invoking the rule. This would take care of any other domains you have pointing to your webspace, along with non www. requests for your real domain. Make sure there is a space between the } and! characters when you make the change, the editing system at WebmasterWorld removes it.