Force 'www' for multiple domains

Whether you are using Linux on the desktop or as a server, it's still good that you're using Linux. Linux related questions go here.

Moderator: General Moderators

Post Reply
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Force 'www' for multiple domains

Post 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
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Force 'www' for multiple domains

Post by AbraCadaver »

Not sure if rewrite supports it, but look at a negative lookbehind expression: (?<!regex)
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Force 'www' for multiple domains

Post 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]
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Re: Force 'www' for multiple domains

Post by alex.barylski »

Cool thanks I'll try that tomorrow when I get into work :)

Cheers,
Alex
Post Reply