Skip to content

Instantly share code, notes, and snippets.

@voneff
Created Jun 12, 2018
Embed
What would you like to do?
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