Created
July 17, 2023 18:47
-
-
Save moaalaa/25bc71a53e17a50d6a115ca00ec234f1 to your computer and use it in GitHub Desktop.
My lovely .htaccess
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> | |
RewriteEngine On | |
# Get Match After www. and access it by %1 | |
# EX: (www.domain.com) will match (domain.com) without www. | |
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC] | |
# Redirect our match %1 (domain.com) with 301 and to HTTPS to not run next HTTPS rule | |
RewriteRule ^(.*)$ https://%1/$1 [R=301,L] | |
RewriteCond %{HTTPS} !=on | |
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R=301,L] | |
# RewriteCond %{HTTPS} !=off | |
# RewriteRule ^/?(.*) http://%{SERVER_NAME}/$1 [R=301,L] | |
RewriteRule ^(.*)$ public/$1 [L] | |
</IfModule> | |
# max-age=25920000 => we till browser to remember to communicate via HTTPS every "300 Day" | |
Header add Strict-Transport-Security "max-age=25920000" | |
# Header add Strict-Transport-Security "max-age=0" | |
# Header always set Strict-Transport-Security "max-age=0; includeSubDomains" | |
# Expiration | |
<IfModule mod_expires.c> | |
ExpiresActive on | |
ExpiresDefault "access plus 1 week" | |
# CSS | |
ExpiresByType text/css "access plus 1 week" | |
# Data interchange | |
ExpiresByType application/json "access plus 0 seconds" | |
ExpiresByType application/xml "access plus 0 seconds" | |
ExpiresByType text/xml "access plus 0 seconds" | |
# Favicon (cannot be renamed!) | |
ExpiresByType image/x-icon "access plus 1 week" | |
# HTML components (HTCs) | |
ExpiresByType text/x-component "access plus 1 week" | |
# HTML | |
ExpiresByType text/html "access plus 0 seconds" | |
# JavaScript | |
ExpiresByType application/javascript "access plus 1 week" | |
# Manifest files | |
ExpiresByType application/x-web-app-manifest+json "access plus 0 seconds" | |
ExpiresByType text/cache-manifest "access plus 0 seconds" | |
# Media | |
ExpiresByType audio/ogg "access plus 1 week" | |
ExpiresByType image/gif "access plus 1 week" | |
ExpiresByType image/jpeg "access plus 1 week" | |
ExpiresByType image/jpg "access plus 1 week" | |
ExpiresByType image/png "access plus 1 week" | |
ExpiresByType video/mp4 "access plus 1 week" | |
ExpiresByType video/ogg "access plus 1 week" | |
ExpiresByType video/webm "access plus 1 week" | |
# Web feeds | |
ExpiresByType application/atom+xml "access plus 1 hour" | |
ExpiresByType application/rss+xml "access plus 1 hour" | |
# Web fonts | |
ExpiresByType application/font-woff "access plus 1 week" | |
ExpiresByType application/vnd.ms-fontobject "access plus 1 week" | |
ExpiresByType application/x-font-ttf "access plus 1 week" | |
ExpiresByType font/opentype "access plus 1 week" | |
ExpiresByType image/svg+xml "access plus 1 week" | |
Header set Cache-Control "public" | |
</IfModule> | |
# Compression | |
<IfModule mod_deflate.c> | |
# Compress HTML, CSS, JavaScript, Text, XML and fonts | |
AddOutputFilterByType DEFLATE application/javascript | |
AddOutputFilterByType DEFLATE application/rss+xml | |
AddOutputFilterByType DEFLATE application/vnd.ms-fontobject | |
AddOutputFilterByType DEFLATE application/x-font | |
AddOutputFilterByType DEFLATE application/x-font-opentype | |
AddOutputFilterByType DEFLATE application/x-font-otf | |
AddOutputFilterByType DEFLATE application/x-font-truetype | |
AddOutputFilterByType DEFLATE application/x-font-ttf | |
AddOutputFilterByType DEFLATE application/x-javascript | |
AddOutputFilterByType DEFLATE application/xhtml+xml | |
AddOutputFilterByType DEFLATE application/xml | |
AddOutputFilterByType DEFLATE font/opentype | |
AddOutputFilterByType DEFLATE font/otf | |
AddOutputFilterByType DEFLATE font/ttf | |
AddOutputFilterByType DEFLATE image/svg+xml | |
AddOutputFilterByType DEFLATE image/x-icon | |
AddOutputFilterByType DEFLATE text/css | |
AddOutputFilterByType DEFLATE text/html | |
AddOutputFilterByType DEFLATE text/javascript | |
AddOutputFilterByType DEFLATE text/plain | |
AddOutputFilterByType DEFLATE text/xml | |
# Remove browser bugs (only needed for really old browsers) | |
BrowserMatch ^Mozilla/4 gzip-only-text/html | |
BrowserMatch ^Mozilla/4\.0[678] no-gzip | |
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html | |
Header append Vary User-Agent | |
</IfModule> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment