Skip to content

Instantly share code, notes, and snippets.

@orlov0562
Created January 10, 2017 19:35
Show Gist options
  • Save orlov0562/08cdb846ffcd2aeebb8e99bc41e59b01 to your computer and use it in GitHub Desktop.
Save orlov0562/08cdb846ffcd2aeebb8e99bc41e59b01 to your computer and use it in GitHub Desktop.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# Redirect old browsers to upgrade page, to support SNI for https
SetEnv SSL_TLS_SNI %{SSL:SSL_TLS_SNI}
RewriteCond %{HTTP_USER_AGENT} MSIE\s[1-8]\. [NC,OR]
RewriteCond %{HTTP_USER_AGENT} Windows\sNT\s5 [NC,OR]
RewriteCond %{HTTP_USER_AGENT} Opera/[1-3]\. [NC,OR]
RewriteCond %{HTTP_USER_AGENT} Safari/[1-4]\. [NC,OR]
RewriteCond %{HTTP_USER_AGENT} Navigator/ [NC,OR]
RewriteCond %{HTTP_USER_AGENT} Android.*(Mobile)?\ [0-3]\. [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^(.*.symbian.*) [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^(.*.blackberry.*) [NC]
RewriteCond %{SSL:SSL_TLS_SNI} =""
RewriteRule .? upgrade.html [L]
# If request is coming not through https, than redirect it to https
# Don't put www. here. If it is already there it will be included, if not
# the subsequent rule will catch it.
RewriteCond %{HTTPS} off
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Now, rewrite any request to the wrong domain to use www.
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment