Skip to content

Instantly share code, notes, and snippets.

@emhaye
Forked from vielhuber/.htaccess
Created October 3, 2018 07:49
Show Gist options
  • Save emhaye/2a2e600fa50a5fb5aa6ac2372f15ece3 to your computer and use it in GitHub Desktop.
Save emhaye/2a2e600fa50a5fb5aa6ac2372f15ece3 to your computer and use it in GitHub Desktop.

Revisions

  1. @vielhuber vielhuber revised this gist Sep 15, 2018. 1 changed file with 5 additions and 1 deletion.
    6 changes: 5 additions & 1 deletion .htaccess
    Original file line number Diff line number Diff line change
    @@ -134,4 +134,8 @@ RewriteRule ^ https://%1.tld.org%{REQUEST_URI} [NE,L,R]
    # RewriteCond %{HTTP_HOST} !\.local$ [NC]
    # RewriteCond %{HTTP_HOST} !\.xip\.io$ [NC]
    # RewriteCond %{HTTP_HOST} ^www\..+$ [NC]
    # RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
    # RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]




  2. @vielhuber vielhuber revised this gist Sep 15, 2018. 1 changed file with 5 additions and 1 deletion.
    6 changes: 5 additions & 1 deletion .htaccess
    Original file line number Diff line number Diff line change
    @@ -91,7 +91,11 @@ RewriteRule ^.*$ https://www.camac-harps.com%{REQUEST_URI} [R,L]




    # # force https
    # RewriteCond %{HTTP_HOST} !\.xip\.io$ [NC]
    # RewriteCond %{HTTP_HOST} !\.local$ [NC]
    # RewriteCond %{HTTPS} !=on [NC]
    # RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

    # force ssl and non-www for main domain and for all subdomains (except local)
    RewriteEngine On
  3. @vielhuber vielhuber revised this gist Sep 15, 2018. 1 changed file with 27 additions and 1 deletion.
    28 changes: 27 additions & 1 deletion .htaccess
    Original file line number Diff line number Diff line change
    @@ -104,4 +104,30 @@ RewriteRule ^ https://tld.org%{REQUEST_URI} [R=301,L,NE]
    RewriteCond %{HTTP_HOST} !^local\.tld\.org$ [NC]
    RewriteCond %{SERVER_PORT} 80
    RewriteCond %{HTTP_HOST} ^((?!www\.)[^.]+)\.tld\.org$
    RewriteRule ^ https://%1.tld.org%{REQUEST_URI} [NE,L,R]
    RewriteRule ^ https://%1.tld.org%{REQUEST_URI} [NE,L,R]

    # # force www except on development machines (.local & .xip.io)
    # RewriteCond %{HTTPS} !=on
    # RewriteCond %{HTTP_HOST} !\.local$ [NC]
    # RewriteCond %{HTTP_HOST} !\.xip\.io$ [NC]
    # RewriteCond %{HTTP_HOST} !^www\..+$ [NC]
    # RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
    # # https
    # RewriteCond %{HTTPS} =on
    # RewriteCond %{HTTP_HOST} !\.local$ [NC]
    # RewriteCond %{HTTP_HOST} !\.xip\.io$ [NC]
    # RewriteCond %{HTTP_HOST} !^www\..+$ [NC]
    # RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

    # # force non-www except on development machines (.local & .xip.io)
    # RewriteCond %{HTTPS} !=on
    # RewriteCond %{HTTP_HOST} !\.local$ [NC]
    # RewriteCond %{HTTP_HOST} !\.xip\.io$ [NC]
    # RewriteCond %{HTTP_HOST} ^www\..+$ [NC]
    # RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
    # # https
    # RewriteCond %{HTTPS} =on
    # RewriteCond %{HTTP_HOST} !\.local$ [NC]
    # RewriteCond %{HTTP_HOST} !\.xip\.io$ [NC]
    # RewriteCond %{HTTP_HOST} ^www\..+$ [NC]
    # RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
  4. @vielhuber vielhuber revised this gist Sep 22, 2017. 1 changed file with 20 additions and 1 deletion.
    21 changes: 20 additions & 1 deletion .htaccess
    Original file line number Diff line number Diff line change
    @@ -85,4 +85,23 @@ RewriteRule ^.*$ https://%1%{REQUEST_URI} [R,L]
    RewriteCond %{HTTP_HOST} !\.local$ [NC]
    RewriteCond %{HTTPS} !=on [OR]
    RewriteCond %{HTTP_HOST} ^camac-harps\.com$ [NC]
    RewriteRule ^.*$ https://www.camac-harps.com%{REQUEST_URI} [R,L]
    RewriteRule ^.*$ https://www.camac-harps.com%{REQUEST_URI} [R,L]







    # force ssl and non-www for main domain and for all subdomains (except local)
    RewriteEngine On
    # main domain
    RewriteCond %{HTTP_HOST} ^(www\.)?tld\.org$ [NC]
    RewriteCond %{HTTPS} off [OR]
    RewriteCond %{HTTP_HOST} ^www\. [NC]
    RewriteRule ^ https://tld.org%{REQUEST_URI} [R=301,L,NE]
    # subdomains
    RewriteCond %{HTTP_HOST} !^local\.tld\.org$ [NC]
    RewriteCond %{SERVER_PORT} 80
    RewriteCond %{HTTP_HOST} ^((?!www\.)[^.]+)\.tld\.org$
    RewriteRule ^ https://%1.tld.org%{REQUEST_URI} [NE,L,R]
  5. @vielhuber vielhuber revised this gist Dec 9, 2016. 1 changed file with 17 additions and 1 deletion.
    18 changes: 17 additions & 1 deletion .htaccess
    Original file line number Diff line number Diff line change
    @@ -69,4 +69,20 @@ RewriteEngine On
    RewriteBase /
    RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
    RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
    </IfModule>
    </IfModule>



    # force ssl and www for main domain, force ssl and non www for all subdomains (except locally)
    RewriteEngine On
    # for subdomains: force ssl and non www
    RewriteCond %{HTTP_HOST} !\.local$ [NC]
    RewriteCond %{HTTPS} !=on
    RewriteCond %{HTTP_HOST} !^(www\.)?camac-harps\.com$ [NC]
    RewriteCond %{HTTP_HOST} ^(?:www\.|)(.*)$ [NC]
    RewriteRule ^.*$ https://%1%{REQUEST_URI} [R,L]
    # for main domains: force ssl and www
    RewriteCond %{HTTP_HOST} !\.local$ [NC]
    RewriteCond %{HTTPS} !=on [OR]
    RewriteCond %{HTTP_HOST} ^camac-harps\.com$ [NC]
    RewriteRule ^.*$ https://www.camac-harps.com%{REQUEST_URI} [R,L]
  6. @vielhuber vielhuber revised this gist Sep 20, 2016. No changes.
  7. @vielhuber vielhuber revised this gist Aug 4, 2016. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions .htaccess
    Original file line number Diff line number Diff line change
    @@ -46,6 +46,10 @@ RewriteCond %{HTTP_HOST} !\.dev$ [NC]
    RewriteCond %{HTTP_HOST} !\.local$ [NC]
    RewriteCond %{HTTP_HOST} !^www\.domain\.de [NC]
    RewriteRule ^(.*)$ https://www.domain.de/$1 [R=301,L]
    RewriteCond %{HTTP_HOST} !\.dev$ [NC]
    RewriteCond %{HTTP_HOST} !\.local$ [NC]
    RewriteCond %{SERVER_PORT} 80
    RewriteRule ^(.*)$ https://www.domain.de/$1 [R=301,L]

    # force www only
    RewriteEngine on
  8. @vielhuber vielhuber revised this gist Aug 3, 2016. 1 changed file with 7 additions and 0 deletions.
    7 changes: 7 additions & 0 deletions .htaccess
    Original file line number Diff line number Diff line change
    @@ -40,6 +40,13 @@ RewriteEngine on
    ...
    </IfModule>

    # not locally #2
    RewriteEngine On
    RewriteCond %{HTTP_HOST} !\.dev$ [NC]
    RewriteCond %{HTTP_HOST} !\.local$ [NC]
    RewriteCond %{HTTP_HOST} !^www\.domain\.de [NC]
    RewriteRule ^(.*)$ https://www.domain.de/$1 [R=301,L]

    # force www only
    RewriteEngine on
    RewriteCond %{HTTP_HOST} !^www\.
  9. @vielhuber vielhuber revised this gist Jun 16, 2016. No changes.
  10. @vielhuber vielhuber revised this gist Apr 14, 2016. 1 changed file with 11 additions and 0 deletions.
    11 changes: 11 additions & 0 deletions .htaccess
    Original file line number Diff line number Diff line change
    @@ -4,6 +4,17 @@ RewriteCond %{HTTP_HOST} (?!^www\.)^(.+)$ [OR]
    RewriteCond %{HTTPS} off
    RewriteRule ^ https://www.%1%{REQUEST_URI} [R=301,L]


    # alternative way
    RewriteCond %{HTTP_HOST} !^$
    RewriteCond %{HTTP_HOST} !^www\. [NC]
    RewriteCond %{HTTPS}s ^on(s)|
    RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
    RewriteCond %{HTTPS} off
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=302,L,NE]



    # without lookbehind
    RewriteEngine On
    RewriteCond %{HTTP_HOST} !^www\.domain\.de [NC]
  11. @vielhuber vielhuber revised this gist Jan 31, 2016. 1 changed file with 7 additions and 0 deletions.
    7 changes: 7 additions & 0 deletions .htaccess
    Original file line number Diff line number Diff line change
    @@ -11,6 +11,13 @@ RewriteRule ^(.*)$ https://www.domain.de/$1 [R=301,L]
    RewriteCond %{SERVER_PORT} 80
    RewriteRule ^(.*)$ https://www.domain.de/$1 [R=301,L]

    # force HTTPS and www not for subdomains
    RewriteCond %{HTTP_HOST} ^domain\.de [NC]
    RewriteRule ^(.*)$ https://www.domain.de/$1 [R=301,L]
    RewriteCond %{HTTP_HOST} ^www\.domain\.de [NC]
    RewriteCond %{SERVER_PORT} 80
    RewriteRule ^(.*)$ https://www.domain.de/$1 [R=301,L]

    # for cloudflare
    RewriteEngine On
    RewriteCond %{HTTP:X-Forwarded-Proto} =http
  12. @vielhuber vielhuber revised this gist Sep 28, 2015. 1 changed file with 16 additions and 1 deletion.
    17 changes: 16 additions & 1 deletion .htaccess
    Original file line number Diff line number Diff line change
    @@ -25,4 +25,19 @@ RewriteEngine on
    # force www only
    RewriteEngine on
    RewriteCond %{HTTP_HOST} !^www\.
    RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
    RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

    # force HTTPS and non-www
    <IfModule !mod_win32.c>
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^(www\.)(.+) [OR]
    RewriteCond %{HTTPS} off
    RewriteCond %{HTTP_HOST} ^(www\.)?(.+)
    RewriteRule ^ https://%2%{REQUEST_URI} [R=301,L]
    </IfModule>
    <IfModule mod_win32.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
    RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
    </IfModule>
  13. @vielhuber vielhuber revised this gist Aug 11, 2015. 1 changed file with 6 additions and 1 deletion.
    7 changes: 6 additions & 1 deletion .htaccess
    Original file line number Diff line number Diff line change
    @@ -20,4 +20,9 @@ RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
    <IfModule !mod_win32.c>
    RewriteEngine on
    ...
    </IfModule>
    </IfModule>

    # force www only
    RewriteEngine on
    RewriteCond %{HTTP_HOST} !^www\.
    RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
  14. @vielhuber vielhuber revised this gist Jul 2, 2015. 1 changed file with 9 additions and 1 deletion.
    10 changes: 9 additions & 1 deletion .htaccess
    Original file line number Diff line number Diff line change
    @@ -5,11 +5,19 @@ RewriteCond %{HTTPS} off
    RewriteRule ^ https://www.%1%{REQUEST_URI} [R=301,L]

    # without lookbehind
    RewriteEngine On
    RewriteCond %{HTTP_HOST} !^www\.domain\.de [NC]
    RewriteRule ^(.*)$ https://www.domain.de/$1 [R=301,L]
    RewriteCond %{SERVER_PORT} 80
    RewriteRule ^(.*)$ https://www.domain.de/$1 [R=301,L]

    # for cloudflare
    RewriteEngine On
    RewriteCond %{HTTP:X-Forwarded-Proto} =http
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

    # not locally
    <IfModule !mod_win32.c>
    RewriteEngine on
    ...
    </IfModule>
  15. @vielhuber vielhuber revised this gist Apr 21, 2015. 1 changed file with 11 additions and 1 deletion.
    12 changes: 11 additions & 1 deletion .htaccess
    Original file line number Diff line number Diff line change
    @@ -2,4 +2,14 @@
    RewriteEngine On
    RewriteCond %{HTTP_HOST} (?!^www\.)^(.+)$ [OR]
    RewriteCond %{HTTPS} off
    RewriteRule ^ https://www.%1%{REQUEST_URI} [R=301,L]
    RewriteRule ^ https://www.%1%{REQUEST_URI} [R=301,L]

    # without lookbehind
    RewriteCond %{HTTP_HOST} !^www\.domain\.de [NC]
    RewriteRule ^(.*)$ https://www.domain.de/$1 [R=301,L]
    RewriteCond %{SERVER_PORT} 80
    RewriteRule ^(.*)$ https://www.domain.de/$1 [R=301,L]

    # for cloudflare
    RewriteCond %{HTTP:X-Forwarded-Proto} =http
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
  16. @vielhuber vielhuber created this gist Apr 21, 2015.
    5 changes: 5 additions & 0 deletions .htaccess
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    # force HTTPS and www.
    RewriteEngine On
    RewriteCond %{HTTP_HOST} (?!^www\.)^(.+)$ [OR]
    RewriteCond %{HTTPS} off
    RewriteRule ^ https://www.%1%{REQUEST_URI} [R=301,L]