Skip to content

Instantly share code, notes, and snippets.

@ewingson
Created December 8, 2018 12:24
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 ewingson/f6d3f685fda4abbdc492d5461a2a9f70 to your computer and use it in GitHub Desktop.
Save ewingson/f6d3f685fda4abbdc492d5461a2a9f70 to your computer and use it in GitHub Desktop.
apache2_directory_rewrite_another_set_of_rules_that_seem_to_make_sense
# match any URL with www and rewrite it to https without the www
RewriteCond %{HTTP_HOST} ^(www\.)(.*) [NC]
RewriteRule (.*) https://%2%{REQUEST_URI} [R=301,L]
# match non https and redirect to https
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment