.htaccess add/remove www to domain redirect


/ Published in: Apache
Save to your folder(s)

Rrewrite "www.domain.com -> domain.com" and viceversa


Copy this code and paste it in your HTML
  1. # Option 1: To rewrite "www.domain.com -> domain.com" uncomment the following lines.
  2. #RewriteCond %{HTTPS} !=on
  3. #RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
  4. #RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
  5.  
  6. # Option 2: To rewrite "domain.com -> www.domain.com" uncomment the following lines.
  7. #RewriteCond %{HTTPS} !=on
  8. #RewriteCond %{HTTP_HOST} !^www\..+$ [NC]
  9. #RewriteCond %{HTTP_HOST} (.+)$ [NC]
  10. #RewriteRule ^(.*)$ http://www.%1/$1 [R=301,L]
  11.  
  12. #common configuration
  13. <IfModule mod_rewrite.c>
  14. Options +FollowSymLinks
  15. RewriteEngine on
  16. RewriteCond %{HTTP_HOST} ^website\.it
  17. RewriteRule ^(.*)$ http://www.website.it/$1 [R=301,L]
  18. </IfModule>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.