Skip to content

Instantly share code, notes, and snippets.

@chetanmadaan
Created February 27, 2020 21:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chetanmadaan/faebde5ca8bd0b0e08462c3428419743 to your computer and use it in GitHub Desktop.
Save chetanmadaan/faebde5ca8bd0b0e08462c3428419743 to your computer and use it in GitHub Desktop.
.htaccess redirect thingy.
# Redirect HTTP with www to HTTPS with www
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# Redirect HTTP without www to HTTPS with www
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# Redirect HTTPS without www to HTTPS with www
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
## 301 Redirects
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment