Skip to content

Instantly share code, notes, and snippets.

@acosonic
Created October 23, 2017 11:01
Show Gist options
  • Save acosonic/403ef2fc9f86a2273f9ae512c85930c7 to your computer and use it in GitHub Desktop.
Save acosonic/403ef2fc9f86a2273f9ae512c85930c7 to your computer and use it in GitHub Desktop.
Apache mod_rewrite .htaccess rule for CakePHP to force HTTPS, but ensure Letsencrypt renew works automatically thru virtualmin
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^.well-known/ - [L,NC]
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment