1

I have:

# BEGIN WithoutWWW
RewriteEngine On
RewriteCond %{HTTP_HOST} ^mysite.com [NC]
RewriteRule ^(.*)$ http://www.mysite.com/$1 [L,R=301]
# END WithoutWWW

But it won't work. I can still access both www and non www versions. What am I doing wrong?

Paul Dessert
  • 6,363
  • 8
  • 47
  • 74

2 Answers2

6

Try:


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

//OR
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule (.*) http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

Sudhir Bastakoti
  • 99,167
  • 15
  • 158
  • 162
1
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.mysite\.com [NC]
RewriteRule ^(.*)$ [R=301,L]
Ashraf
  • 2,612
  • 1
  • 20
  • 35