Skip to content

Instantly share code, notes, and snippets.

@cuschk
Last active November 8, 2017 13:54
Show Gist options
  • Save cuschk/678dc57b19e230dae69f to your computer and use it in GitHub Desktop.
Save cuschk/678dc57b19e230dae69f to your computer and use it in GitHub Desktop.
Redirect HTTP requests to a certain domain using HTTPS
RewriteEngine On
RewriteBase /
# don't rewrite robots.txt
RewriteRule ^robots.txt$ - [L]
# redirect all requests to example.com with HTTPS
RewriteCond %{HTTP_HOST} !^example\.com$ [NC]
RewriteRule ^(.*)$ https://example.com/$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