Skip to content

Instantly share code, notes, and snippets.

@voneff
Created June 12, 2018 14:45
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 voneff/bed412ac2a9fc8b7dbfb7362158c32dd to your computer and use it in GitHub Desktop.
Save voneff/bed412ac2a9fc8b7dbfb7362158c32dd to your computer and use it in GitHub Desktop.
WordPress: Redirect all to HTTPS, set HSTS
# BEGIN Redirect to HTTPS and set HSTS
#
# Sources:
# https://stackoverflow.com/questions/40154500/hsts-301s-http-www-to-https-canonical-htaccess
#
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.+) [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [NE,L,R=301]
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [NE,L,R=301]
<IfModule mod_headers.c>
Header set Strict-Transport-Security "max-age=31536000" env=HTTPS
</IfModule>
# END Redirect to HTTPS and set HSTS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment