Loreto Gabawa Jr.
Loreto Gabawa Jr.

Reputation: 2056

.htaccess redirection - two sharing websites

I have two websites that is actually the same where example.com shares all files from examples.com. So whatever changes made in exampples.com, example.com automatically gets updated. That means they have the same .htaccess file. The problem is, I want to both sites redirects to non www to a www url. I got this:

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

Upvotes: 0

Views: 84

Answers (3)

Dolbz
Dolbz

Reputation: 2106

This should do it:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^example\.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^examples\.com$ [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

Basically you're adding an OR condition to say if either example.com or examples.com doesn't begin with www. then add it to the respective domain name.

Upvotes: 1

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 799062

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

Upvotes: 2

Mathieu
Mathieu

Reputation: 5695

replace example.com with %{HTTP_HOST} to make your rules host independent

Upvotes: 0

Related Questions