Skip to content

Instantly share code, notes, and snippets.

@orlov0562
Created January 10, 2017 19:35
Show Gist options
  • Select an option

  • Save orlov0562/08cdb846ffcd2aeebb8e99bc41e59b01 to your computer and use it in GitHub Desktop.

Select an option

Save orlov0562/08cdb846ffcd2aeebb8e99bc41e59b01 to your computer and use it in GitHub Desktop.

Revisions

  1. orlov0562 created this gist Jan 10, 2017.
    28 changes: 28 additions & 0 deletions Not SNI browsers redirect to upgrade page
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    <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>