Blog

Mein privates Blog über allerlei nützliches rund um Internet, Webprogrammierung und was ich sonst so finde.

Force https & www redirect with .htaccess

# -----------------------------------------------------------------
# | Forcing www |
# -----------------------------------------------------------------
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{SERVER_ADDR} !=127.0.0.1
    RewriteCond %{SERVER_ADDR} !=::1
    RewriteCond %{HTTP_HOST} !^www\.
    RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>

# -----------------------------------------------------------------
# | Forcing `https://` |
# -----------------------------------------------------------------
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{ENV:HTTPS} !on
    RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>

Target IE10 only with CSS

Litte trick to target IE10 only for CSS stuff. You should mostly avoid this, but it is sometimes necessary.

In Head:

<!-- [if !IE]><!-->
  <script>
    if (/*@cc_on!@*/false && document.documentMode === 10) {
        document.documentElement.className+=' ie10';
    }
  </script>
<!--<![endif]-->

In CSS:

html.ie10 {
 …
}