Skip to content

Instantly share code, notes, and snippets.

@hostz-frank
Last active March 18, 2019 17:40
Show Gist options
  • Save hostz-frank/8e4e70729116f1ef2b6ff0f7798dbb33 to your computer and use it in GitHub Desktop.
Save hostz-frank/8e4e70729116f1ef2b6ff0f7798dbb33 to your computer and use it in GitHub Desktop.
Efficient redirection for faster load times
# .htaccess
########################################################################
#### ONLY ONE OF THE NEXT TWO BLOCKS BELOW IS FOR YOU! Don't copy both!!
########################################################################
# Redirect to https://www - PLEASE ADJUST YOUR DOMAIN NAME (RewriteRule line)!
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTPS} !=on [OR]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^/?(.*) https://www.example.com/$1 [R=301,L]
</IfModule>
# Redirect to https:// and eliminating leading "www" - ADJUST YOUR DOMAIN NAME (RewriteRule line)!
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTPS} !=on [OR]
RewriteCond %{HTTP_HOST} ^www\.
RewriteRule ^/?(.*) https://example.com/$1 [R=301,L]
</IfModule>
#############################################################################################
#### NEXT LINES CAN BE DANGEROUS ! IF YOU DO NOT UNDERSTAND HSTS DO NOT USE THE LINES BELOW!!
#############################################################################################
# Required in this form for deployment of your domain to internal browser lists using https://hstspreload.org/
<IfModule mod_headers.c>
Header set Strict-Transport-Security "Strict-Transport-Security: max-age=63072000; includeSubDomains; preload" env=HTTPS
</IfModule>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment