redirect to www. domain without needing to hardcode domain


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



Copy this code and paste it in your HTML
  1. <IfModule mod_rewrite.c>
  2. RewriteEngine On
  3. RewriteBase /
  4. # redirect non-www to www
  5. RewriteCond %{HTTP_HOST} ^([a-z-]+)\.([a-z]{2,6})$ [NC]
  6. RewriteRule ^(.*)$ http://www.%1\.%2/$1 [R=301,L]
  7. </IfModule>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.