Skip to content

Instantly share code, notes, and snippets.

@developer-anuragsingh
Last active November 8, 2022 12:34
Show Gist options
  • Save developer-anuragsingh/23ca9ddb1eb4266126ca6b98a4f59323 to your computer and use it in GitHub Desktop.
Save developer-anuragsingh/23ca9ddb1eb4266126ca6b98a4f59323 to your computer and use it in GitHub Desktop.
301 redirect www to non-www & 301 Redirect HTTP to HTTPS
# BEGIN Redirects
RewriteEngine On
# 301 redirect www to non-www
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
# 301 redirect non-www to www
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# 301 redirect to https
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# END Redirects
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment