-
-
Save gwokudasam/76a41649a494a6650a2b64cf3ed04ce1 to your computer and use it in GitHub Desktop.
www & https
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RewriteEngine on | |
### WWW & HTTPS | |
# Force www. | |
RewriteCond %{HTTP_HOST} !^www\. [NC] | |
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301] | |
# Force non-www: | |
RewriteEngine on | |
RewriteCond %{HTTP_HOST} ^www\.example\.com [NC] | |
RewriteRule ^(.*)$ http://example.com/$1 [L,R=301] | |
# or this | |
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC] | |
RewriteRule ^(.*)$ https://%1/$1 [R=301,L] | |
# Force https | |
RewriteCond %{HTTP:X-Forwarded-Proto} !https | |
RewriteCond %{HTTPS} off | |
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] | |
# Redirect old url to new. | |
#<IfModule mod_rewrite.c> | |
RewriteEngine On | |
RewriteCond %{HTTP_HOST} ^olddomain.com$ [OR] | |
RewriteCond %{HTTP_HOST} ^www.olddomain.com$ | |
RewriteRule (.*)$ http://www.newdomain.com/$1 [R=301,L] | |
#</IfModule> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment