Closed yaaax closed 1 year ago
Voici le .htaccess au complet :
AuthUserFile /home/ecoindex.neutral.hosting/public_html/.htpasswd
AuthType Basic
AuthName "Accès réservé"
Require valid-user
RewriteEngine On
# redirect result without params to to 404
RewriteCond %{REQUEST_URI} ^/resultat/index\.html$
RewriteCond %{QUERY_STRING} !(^|&)id($|&)
RewriteRule ^(.*)$ /404.html? [L,R=301]
# prevent bandwith theft from assets
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?:\/\/(.+\.)?ecoindex\.(fr|neutral\.hosting) [NC]
RewriteRule .*\.(jp(e)?g|gif|bmp|png|svg|mp4|webm)$ https://imgur.com/ZtXiCBw.gif [L,R]
# enforce https
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# remove www
RewriteCond %{HTTP_HOST} ^www\.example\.com [NC]
RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]
# Don't allow anyone to see my .htaccess file
<Files .htaccess>
Order allow,deny
Deny from all
</Files>
<IfModule mod_expires.c>
# Sets or disables the cache.
ExpiresActive On
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType image/svg+xml "access plus 1 year"
ExpiresByType text/css "access plus 1 year"
ExpiresByType application/javascript "access plus 1 year"
</IfModule>
<IfModule mod_headers.c>
# Sets or disables the cache.
<filesMatch "\.(jpe?g|png|svg|css|js)$">
Header set Cache-Control "max-age=31536000, public"
</filesMatch>
</IfModule>
<IfModule mod_deflate.c>
# Enables Gzip compression.
SetOutputFilter DEFLATE
AddOutputFilterByType DEFLATE text/html text/css application/x-javascript image/svg+xml
</IfModule>
# Prevents browsing directories.
Options -Indexes
ErrorDocument 404 /404/
Some complements ? Gzip seems already activated, but, who knows.
<IfModule mod_deflate.c>
# Enables Gzip compression.
SetOutputFilter DEFLATE
AddOutputFilterByType DEFLATE text/html text/css application/x-javascript
</IfModule>
# Prevents browsing directories.
Options -Indexes
(we could add gzip on svg if we plan to load svg as external resources)
Updated on prod.
Comment updated: https://github.com/cnumr/EcoIndex/issues/103#issuecomment-1242016251
(we could add gzip on svg if we plan to load svg as external resources)
We do that for the logos right? (or externally means "from another server"?)
Gzip compression will only apply to resources loaded by the network (like <img src="logo.svg" />
, for a svg).
We could add it, just in case (the same logic apply to caching).
Yes 👍
<img src="/images/logo.svg" width="132" height="36" alt="ecoIndex, retour à la page d’accueil">
<img src="/images/logo-greenit.png" width="126" height="50" alt="Association Green IT (prononcer grine • aïe • ti)">
I've updated the .htaccess on the server + updated the comment ☝️
(added: image/svg+xml
)
Done. Efficient client-side caching and network compression.
First draft by @AwebsomeFr and @DocRoms :