Skip to content

Instantly share code, notes, and snippets.

@MahmoudSayed96
Created July 12, 2022 13:42
Show Gist options
  • Save MahmoudSayed96/eb02d0cb54a57cda5bd52ae38cd8fe5c to your computer and use it in GitHub Desktop.
Save MahmoudSayed96/eb02d0cb54a57cda5bd52ae38cd8fe5c to your computer and use it in GitHub Desktop.
apache2 redirect to https with www (https:/www.)
# source: https://simonecarletti.com/blog/2016/08/redirect-domain-http-https-www-apache/
# To redirect all users to access the site WITH the 'https://www.
RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://www.%1%{REQUEST_URI} [L,NE,R=301]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment