0

I currently use:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.e-innovate.co.uk [NC]
RewriteRule ^(.*)$ http://e-innovate.co.uk/$1 [L,R=301,NC]

But what i am trying to do is create a general rewrite code which i can drop into .htaccess files without having to change the domain name such as below, i dont seem to be able to get this to work, am i on the right track ?

Thanks

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [R=301,L]
Frank
  • 1
  • possible duplicate of [Generic htaccess redirect www to non-www](http://stackoverflow.com/questions/234723/generic-htaccess-redirect-www-to-non-www) – arco444 Jan 23 '15 at 13:02
  • hi i tried this already and it gives me a redirect loop – Frank Jan 23 '15 at 13:08

1 Answers1

0

Try:

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

note that this will also get applied to subdomains.

Jon Lin
  • 142,182
  • 29
  • 220
  • 220