Return to Snippet

Revision: 72634
at October 3, 2017 05:55 by apphp-snippets


Initial Code
# Force the www.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^your-site.com [NC]
RewriteRule ^(.*)$ http://www.your-site.com/$1 [L,R=301]
 
# Remove the www.
RewriteEngine On
RewriteCond %{HTTP_HOST} !^your-site.com$ [NC]
RewriteRule ^(.*)$ http://your-site.com/$1 [L,R=301]

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

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

Initial Title
Force www./no-www. in .htaccess

Initial Tags
htaccess

Initial Language
Bash