Redirect www to non www and vice versa

No Comments

To redirect from http:// to http://www. (non www to www)


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

 

To redirect from http://www. to http:// ,(www to non www)


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

 

To redirect from http:// to http://www. , and also remove the route file (index.php) in the url, put these lines on your htaccess :


    RewriteEngine on
    RewriteCond %{HTTP_HOST} !^www.domain.com$ [NC]
    RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301]
    RewriteCond $1 !^(index\.php|images|css|js|styles|robots\.txt)
    RewriteRule ^(.*)$ /index.php/$1 [L]

About us and this blog

We are a digital marketing company with a focus on helping our customers achieve great results across several key areas.

Request a free quote

We offer professional SEO services that help websites increase their organic search score drastically in order to compete for the highest rankings even when it comes to highly competitive keywords.

Subscribe to our newsletter!

More from our blog

See all posts
No Comments

    Leave a Comment