Skip to content

Instantly share code, notes, and snippets.

@rotten77
Last active October 22, 2018 18:41
Show Gist options
  • Save rotten77/7672cd9d773ba1f1fd42 to your computer and use it in GitHub Desktop.
Save rotten77/7672cd9d773ba1f1fd42 to your computer and use it in GitHub Desktop.
# basic
RewriteEngine on
RewriteBase /
ErrorDocument 404 /404.html
# https
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# always "www" variant
RewriteCond %{HTTP_HOST} ^domain\.com
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301]
# always "no-www" variant
RewriteCond %{HTTP_HOST} ^www\.domain\.com
RewriteRule ^(.*)$ http://domain.com/$1 [L,R=301]
# redirect to other domain (with required url)
RewriteRule ^(.*)$ http://www.new-domain.com/$1 [R=301,L,QSA]
# redirect to other domain (all to root)
RewriteRule ^(.*)$ http://www.new-domain.com/ [R=301,L,QSA]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment