Skip to content

Instantly share code, notes, and snippets.

@apphp
Created September 21, 2017 15:57
Show Gist options
  • Save apphp/6b6c3e3a9416c95f4b7e77df07445844 to your computer and use it in GitHub Desktop.
Save apphp/6b6c3e3a9416c95f4b7e77df07445844 to your computer and use it in GitHub Desktop.
Force www./no-www. in .htaccess
# source: http://apphp.com/index.php?snippet=htaccess-www-or-no-www
# 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]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment