Forum Moderators: phranque
RewriteEngine On
RewriteCond %{HTTP_HOST}!^www\.widget1\.info
RewriteRule (.*) [widget1.info...] [R=301,L]
RewriteCond %{HTTP_HOST}!^www\.widget2\.info
RewriteRule (.*) [widget2.info...] [R=301,L]
RewriteCond %{HTTP_HOST}!^www\.widget3\.info
RewriteRule (.*) [widget3.info...] [R=301,L]
I think I need a non-domain-specific regular expression? (The rewrite of non-www to www should executed regardless of whether the domain is widget1, widget2 or widget3.)
Unfortunately, I have no idea how to do this. Any tips would be appreciated. I've looked through many of the older posts regarding this issue, but all of them seem have been created with one specific domain in mind.
# enable rewrite engine
RewriteEngine on
# if requested hostname does NOT start with "www."
RewriteCond %{HTTP_HOST} !^www\.
# get hostname to %1 variable
RewriteCond %{HTTP_HOST} ^([a-z]+\.[a-z]+)
# prepend "www." to requested hostname and file
RewriteRule (.*) http://www.%1/$1 [R=301,L]
# enable rewrite engine
RewriteEngine on
# if requested hostname does NOT start with "www."
RewriteCond %{HTTP_HOST} !^www\.
# and if one of three hostnames, then get it to %1 variable
RewriteCond %{HTTP_HOST} ^(domain1\.com¦domain2\.info¦domain3\.uk\.com)
# prepend "www." to requested hostname and file
RewriteRule (.*) http://www.%1/$1 [R=301,L]
For more information, see the documents cited in our forum charter [webmasterworld.com] and the tutorials in the Apache forum section of the WebmasterWorld library [webmasterworld.com].
[edited by: jdMorgan at 6:31 pm (utc) on Sep. 4, 2006]