Add and remove www to urls through .htaccess


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

Add and remove www to urls through .htaccess with mod_rewrite


Copy this code and paste it in your HTML
  1. # add www to any url
  2. RewriteEngine on
  3. RewriteCond %{HTTP_HOST} !^www\.domain\.com [NC]
  4. RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301]
  5.  
  6.  
  7. # remove www from any url
  8. Options +FollowSymlinks
  9. RewriteEngine on
  10. RewriteCond %{HTTP_HOST} ^www\.domain\.com [NC]
  11. RewriteRule ^(.*)$ http://domain.com/$1 [L,R=301]

URL: http://www.barattalo.it/2010/05/02/10-htaccess-usefull-tips/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.