Skip to content

Instantly share code, notes, and snippets.

@cuschk
Last active August 31, 2017 12:04
Show Gist options
  • Save cuschk/d8535e149a731645a4d5 to your computer and use it in GitHub Desktop.
Save cuschk/d8535e149a731645a4d5 to your computer and use it in GitHub Desktop.
Redirect HTTP requests to non-www HTTPS
RewriteEngine On
RewriteBase /
# don't rewrite robots.txt
RewriteRule ^robots.txt$ - [L]
# redirect to non-www
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
# redirect non-HTTPS to HTTPS
RewriteCond %{HTTPS} Off [or]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment