Skip to content

Instantly share code, notes, and snippets.

@froemken
Last active May 9, 2018 10:01
Show Gist options
  • Save froemken/723c60ba1bcd1187660f78f110caa740 to your computer and use it in GitHub Desktop.
Save froemken/723c60ba1bcd1187660f78f110caa740 to your computer and use it in GitHub Desktop.
Redirect domains to https ssl and prepend www
# You can check you .htaccess with: https://htaccess.madewithlove.be/
RewriteEngine On
# First: rewrite domains to different targets
RewriteCond %{HTTP_HOST} sfroemken-old\.de$ [NC]
RewriteRule ^(.*)$ https://www.sfroemken-new.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} another-domain-old\.cc$ [NC]
RewriteRule ^(.*)$ https://www.another-domain-new.com/$1 [R=301,L]
# Second: Prepend www to all other domains, if not already done
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Third: Rewrite to HTTPS
# You can't create redirects for HTTPS domains which don't have a SSL certificate,
# as the request will not reach the .htaccess file.
- That's why this part has to be the last part.
RewriteCond %{HTTPS} off
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment