Skip to content

Instantly share code, notes, and snippets.

@shibbirweb
Last active December 28, 2020 09:53
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 shibbirweb/147ee1a13529b3b8acbd44e0e42ca570 to your computer and use it in GitHub Desktop.
Save shibbirweb/147ee1a13529b3b8acbd44e0e42ca570 to your computer and use it in GitHub Desktop.
Redirect non-www to www & http to https .htaccess scripts
RewriteEngine On
#redirect non-www to www for all domain
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
#redirect non-www to www for specific domain
RewriteCond %{HTTP_HOST} ^example\.com
RewriteRule ^(.*)$ http://www.example.com/$1 [R=permanent,L]
#redirect http to https
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