L
L
lipinart2017-08-04 09:27:55
htaccess
lipinart, 2017-08-04 09:27:55

How to write htaccess for a static site?

Mini-site of 5 html-pages.
- Remove index.html from url
- hotlink protection
- gzip compression
- duplicates from www
- 404 redirect
- how to set up caching and is it necessary for statics at all?
In the end, this is what happened:

Options All -ExecCGI -Indexes -Includes +FollowSymLinks

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteBase /
    RewriteCond %{HTTP_HOST} ^mysite
    RewriteRule (.*) http://www.black-web.ru/$1 [R=301,L]
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.html\ HTTP/
    RewriteRule ^index\.html$ http://www.mysite.ru/ [R=301,L]
</IfModule>

DirectoryIndex index.html

<IfModule mod_setenvif.c>
  SetEnv TZ Europe/Moscow
</IfModule>
ServerSignature Off

<IfModule mod_gzip.c>
    mod_gzip_on         Yes
    mod_gzip_dechunk    Yes
    mod_gzip_item_include file		\.(html?|txt|css|js|)$
    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>

<ifModule mod_headers.c>
    <FilesMatch "\.(html|htm)$">
        Header set Cache-Control "max-age=43200"
    </FilesMatch>
    <FilesMatch "\.(js|css)$">
        Header set Cache-Control "max-age=604800"
    </FilesMatch>
    <FilesMatch "\.(ico|gif|jpg|jpeg|png)$">
        Header set Cache-Control "max-age=2592000"
    </FilesMatch>

</IfModule>


# Bad Rquest
ErrorDocument 400 /400.html
# Authorization Required
ErrorDocument 401 /index.html
# Forbidden
ErrorDocument 403 /index.html
# Not found
ErrorDocument 404 /index.html
# Method Not Allowed
ErrorDocument 405 /index.html
# Request Timed Out
ErrorDocument 408 /index.html
# Request URI Too Long
ErrorDocument 414 /index.html
# Internal Server Error
ErrorDocument 500 /index.html
# Not Implemented
ErrorDocument 501 /index.html
# Bad Gateway 
ErrorDocument 502 /index.html
# Service Unavailable 
ErrorDocument 503 /index.html
# Gateway Timeout
ErrorDocument 504 /index.html

How true and appropriate?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question