.htaccess

Categories: Web

Je textový soubor .htaccess určující zvláštní vlastnosti serveru. Díky němu lze nastavit:

Příklad zápisu

Chybová stránka při chybě 404:

ErrorDocument 404 /chyba.html

Jednoduchý zápis obyčejného cashování:

<IfModule mod_expires.c>
ExpiresActive On 
ExpiresDefault A600 
ExpiresByType text/javascript A604800 
ExpiresByType application/javascript A604800 
ExpiresByType text/css A604800 
ExpiresByType image/gif A604800 
ExpiresByType image/png A604800 
ExpiresByType image/jpeg A604800 
ExpiresByType image/x-icon A604800 
ExpiresByType text/html A60
</IfModule>

Ověřené řešení s kompresí a optimalizacemi:

<ifModule mod_deflate.c>
AddOutputFilterByType DEFLATE \
 text/html \
 text/xml \
 text/css \
 text/plain \
 image/svg+xml \
 application/xhtml+xml \
 application/xml \
 application/rdf+xml \
 application/rss+xml \
 application/atom+xml \
 text/javascript \
 text/ecmascript \
 application/javascript \
 application/x-javascript \
 application/ecmascript \
 application/json \
 application/x-font-ttf \
 application/x-font-otf \
 font/truetype \
 font/opentype \
 application/x-pointplus
</ifModule>

<ifModule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus 2592000 seconds"
ExpiresByType image/x-icon "access plus 2592000 seconds"
ExpiresByType image/jpeg "access plus 2592000 seconds"
ExpiresByType image/jpg "access plus 2592000 seconds"
ExpiresByType image/png "access plus 2592000 seconds"
ExpiresByType image/gif "access plus 2592000 seconds"
ExpiresByType application/x-shockwave-flash "access plus 2592000 seconds"
ExpiresByType text/css "access plus 604800 seconds"
ExpiresByType text/javascript "access plus 604800 seconds"
ExpiresByType application/javascript "access plus 604800 seconds"
ExpiresByType application/x-javascript "access plus 604800 seconds"
ExpiresByType text/html "access plus 604800 seconds"
ExpiresByType application/xhtml+xml "access plus 604800 seconds"
</ifModule>

<ifModule mod_headers.c>
<filesMatch "\.(ico|jpe?g|png|gif|swf)$">
Header set Cache-Control "public"
</filesMatch>
<filesMatch "\.(css)$">
Header set Cache-Control "public"
</filesMatch>
<filesMatch "\.(js)$">
Header set Cache-Control "private"
</filesMatch>
<filesMatch "\.(x?html?|php)$">
Header set Cache-Control "private, max-age=360, must-revalidate"
</filesMatch>
</ifModule>

Header unset Pragma
FileETag None
Header unset ETag

Zákaz pro IP 223.121.232.123:

deny from 223.121.232.123

Zákaz pro celý blok adres:

deny from 223

    Napsat komentář

    Vaše emailová adresa nebude zveřejněna. Vyžadované informace jsou označeny *