Page 1 of 1

Force 'www' for multiple domains

Posted: Wed Dec 08, 2010 11:29 am
by alex.barylski
We have all seen the examples of forcing a 'www'sub-domain, thus preventing search engines from seeing two copies of a web site (non-www and www).

Code: Select all

  RewriteCond %{HTTP_HOST} ^test\.com$ [NC]
  RewriteRule ^(.*)$ http://www.test.com/$1 [L,R=301]
This works great, with one exception. I need to apply this rule using a wildcard or optional suffix so that domains like:

testproducts.com
teststuff.net
testingmaterial.com

Are also included in that query and force 'www' subdomain, is this possible?

Cheers,
Alex

Re: Force 'www' for multiple domains

Posted: Wed Dec 08, 2010 12:58 pm
by AbraCadaver
Not sure if rewrite supports it, but look at a negative lookbehind expression: (?<!regex)

Re: Force 'www' for multiple domains

Posted: Wed Dec 08, 2010 2:27 pm
by AbraCadaver
AbraCadaver wrote:Not sure if rewrite supports it, but look at a negative lookbehind expression: (?<!regex)
Doh, might be even easier with the expressions in mod rewrite now that I think about it (not tested):

[text]RewriteCond %{HTTP_HOST} !^www\. [NC]
ReriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [L,R=301][/text]

Re: Force 'www' for multiple domains

Posted: Wed Dec 08, 2010 7:48 pm
by alex.barylski
Cool thanks I'll try that tomorrow when I get into work :)

Cheers,
Alex