Skip to content

Instantly share code, notes, and snippets.

@lcloss
Last active November 28, 2019 23:48
Show Gist options
  • Save lcloss/17c22663ecfab58151ccb4f67c175744 to your computer and use it in GitHub Desktop.
Save lcloss/17c22663ecfab58151ccb4f67c175744 to your computer and use it in GitHub Desktop.
Example of a safer and more performative .htaccess
<IfModule mod_headers.c>
Header set Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" env=HTTPS
Header always set Content-Security-Policy "default-src 'self' *.cloudflare.com *.google-analytics.com; script-src 'self' 'unsafe-inline' 'unsafe-eval' *.cloudflare.com *.google-analytics.com https://sharebutton.net *.sharebutton.net; style-src 'self' 'unsafe-inline'; img-src data: *; object-src 'none'"
Header set X-Content-Type-Options nosniff
Header set X-Frame-Options DENY
Header set X-XSS-Protection "1; mode=block"
Header always set Referrer-Policy "same-origin"
Header always set Feature-Policy "microphone 'none'; payment 'none'; sync-xhr 'self' https://o-seu-dominio.com"
</IfModule>
# Compressão com deflate
<IfModule mod_deflate.c>
# Compactar por tipo - html, text, css, xml
AddOutputFilterByType DEFLATE text/html text/plain text/css text/xml
# Compactar por tipo - javascript
AddOutputFilterByType DEFLATE application/x-javascript application/javascript text/javascript text/x-js text/x-javascript
# Compactar por extensão
AddOutputFilter DEFLATE js css htm html xml ttf eot
</IfModule>
# Compressão com GZip
<IfModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file \.(html?|txt|css|js|php|pl|ttf|eot)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</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 month"
ExpiresByType text/html "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 1 week"
</IfModule>
## EXPIRES CACHING ##
RewriteEngine On
# Some hosts may require you to use the "RewriteBase" directive
# If you need to use the "RewriteBase" directive, it should be the
# absolute physical path to the directory that contains this htaccess file.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment