Skip to content

Instantly share code, notes, and snippets.

@seb86
Created April 19, 2017 14:39
Show Gist options
  • Save seb86/10e211e5221a935bbb17d8ef1475b8b0 to your computer and use it in GitHub Desktop.
Save seb86/10e211e5221a935bbb17d8ef1475b8b0 to your computer and use it in GitHub Desktop.
Generic htaccess redirect www to non-www
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
@seb86
Copy link
Author

seb86 commented Apr 19, 2017

Or you could try this one.

RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.
RewriteCond %{HTTPS}s ^on(s)|offs
RewriteRule ^ http%1://example.com%{REQUEST_URI} [NE,L,R]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment