Posted By

apphp-snippets on 10/03/17


Tagged

htaccess force wwwno-www


Versions (?)

Force www./no-www. in .htaccess


 / Published in: Bash
 

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

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

  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]

Report this snippet  

You need to login to post a comment.