Force www./no-www. in .htaccess


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

This example shows you how to force www. or no-www. using .htaccess file.


Copy this code and paste it in your HTML
  1. # Force the www.
  2. RewriteEngine On
  3. RewriteCond %{HTTP_HOST} ^your-site.com [NC]
  4. RewriteRule ^(.*)$ http://www.your-site.com/$1 [L,R=301]
  5.  
  6. # Remove the www.
  7. RewriteEngine On
  8. RewriteCond %{HTTP_HOST} !^your-site.com$ [NC]
  9. RewriteRule ^(.*)$ http://your-site.com/$1 [L,R=301]

URL: http://www.apphp.com/index.php?snippet=htaccess-www-or-no-www

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.