-
-
Save olekhy/90023b4b9dfd6ab84e36d2fe9c224ba3 to your computer and use it in GitHub Desktop.
A base .htaccess with HTTPS redirect behind an AWS Load Balancer #apache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<IfModule mod_rewrite.c> | |
<IfModule mod_negotiation.c> | |
Options -MultiViews | |
</IfModule> | |
RewriteEngine On | |
# Force HTTPS - Proto needed for AWS ELB | |
RewriteCond %{HTTP:X-Forwarded-Proto} !https | |
RewriteCond %{HTTP_USER_AGENT} !^ELB-HealthChecker | |
RewriteRule ^.*$ https://%{HTTP:Host}%{REQUEST_URI} [L,R=permanent] | |
# Redirect Trailing Slashes If Not A Folder... | |
RewriteCond %{REQUEST_FILENAME} !-d | |
RewriteRule ^(.*)/$ /$1 [L,R=301] | |
# Handle Front Controller... | |
RewriteCond %{REQUEST_FILENAME} !-d | |
RewriteCond %{REQUEST_FILENAME} !-f | |
RewriteRule ^(.*)$ index.php/$1 [L] | |
# Handle Authorization Header | |
RewriteCond %{HTTP:Authorization} . | |
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] | |
</IfModule> | |
## EXPIRES CACHING ## | |
<IfModule mod_expires.c> | |
ExpiresActive On | |
ExpiresByType image/jpg "access 1 year" | |
ExpiresByType image/jpeg "access 1 year" | |
ExpiresByType image/gif "access 1 year" | |
ExpiresByType image/png "access 1 year" | |
ExpiresByType text/css "access 1 week" | |
ExpiresByType text/html "access 1 week" | |
ExpiresByType application/pdf "access 1 month" | |
ExpiresByType text/x-javascript "access 1 week" | |
ExpiresByType application/x-shockwave-flash "access 1 month" | |
ExpiresByType image/x-icon "access 1 year" | |
ExpiresDefault "access 1 month" | |
</IfModule> | |
## EXPIRES CACHING ## | |
<IfModule mod_deflate.c> | |
# Insert filter | |
SetOutputFilter DEFLATE | |
# Don't compress images | |
SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png|html)$ no-gzip dont-vary | |
# Make sure proxies don't deliver the wrong content | |
Header append Vary User-Agent env=!dont-vary | |
</IfModule> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment