Skip to content

Instantly share code, notes, and snippets.

@gwokudasam
Forked from hectorromo/.htaccess
Created October 3, 2019 06:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gwokudasam/76a41649a494a6650a2b64cf3ed04ce1 to your computer and use it in GitHub Desktop.
Save gwokudasam/76a41649a494a6650a2b64cf3ed04ce1 to your computer and use it in GitHub Desktop.
www & https
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