Skip to content

Instantly share code, notes, and snippets.

@antoniputra
Created May 5, 2014 06:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save antoniputra/e53e4db5fa1ad5d0beab to your computer and use it in GitHub Desktop.
Save antoniputra/e53e4db5fa1ad5d0beab to your computer and use it in GitHub Desktop.
Force domain with or without www on .htaccess
# FORCE USING WWW
RewriteEngine On
RewriteCond %{HTTP_HOST} ^your-site.com [NC]
RewriteRule ^(.*)$ http://www.your-site.com/$1 [L,R=301]
# FORCE REMOVE 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