Skip to content

Instantly share code, notes, and snippets.

@alrnz
Last active May 8, 2019 08:49
Show Gist options
  • Save alrnz/a50e14286df4d0e86000 to your computer and use it in GitHub Desktop.
Save alrnz/a50e14286df4d0e86000 to your computer and use it in GitHub Desktop.
htaccess redirects for www and https #htaccess
# redirect to german page
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} !=on
# domain matches
RewriteCond %{HTTP_HOST} ^www.domain\.de$ [NC]
# path is empty
RewriteCond %{REQUEST_URI} ^/$
RewriteCond %{SERVER_ADDR} !=127.0.0.1
RewriteCond %{SERVER_ADDR} !=::1
RewriteRule ^(.*)$ http://www.domain.de/test/ [L,R=301]
</IfModule>
# redirect to www
<IfModule mod_rewrite.c>
RewriteEngine On
# not https
RewriteCond %{HTTPS} !=on
# not www
RewriteCond %{HTTP_HOST} !^www\. [NC]
# domain matches (possible with \.de
RewriteCond %{HTTP_HOST} ^my-domain\. [NC]
RewriteCond %{SERVER_ADDR} !=127.0.0.1
RewriteCond %{SERVER_ADDR} !=::1
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</IfModule>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment