16 Useful .htaccess Tricks and Hacks For Web Developers

Posted on 05. Jul, 2009 by Administrator in tutorials


Il file .htaccess (Hypertext Access file) č un tool molto potente di apache. Il file .htaccess č un semplice testo ASCII da mettere nella directory del nostro sito web
text. Puoi creare un file .htaccess usando un editor di testi come notepad.

1. Ridirezionare gli errori su opportune pagine

ErrorDocument 401 /error/401.php
ErrorDocument 403 /error/403.php
ErrorDocument 404 /error/404.php
ErrorDocument 500 /error/500.php

2. Come settare la timezone sul server

SetEnv TZ America/Houston

3. Bloccare indirizzo ip

allow from all
deny from 145.186.14.122
deny from 124.15

Gli ip bannati vedreanno un errore 403

4. SEO Friendly 301 redirect per vecchi links

Redirect 301 /d/file.html http://www.htaccesselite.com/r/file.html

5. Settare email dell'amministratore del server

ServerSignature EMail
SetEnv SERVER_ADMIN default@domain.com

6. Prevenire i link diretti alle immagini per prevenire ridimensionamento consumo banda

Options +FollowSymlinks
# Protect Hotlinking
RewriteEngine On
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?domainname\.com/ [nc]
RewriteRule .*\.(gif|jpg|png)$ http://domainname.com/img/hotlink_f_o.png [nc]

7. Limitare l'accesso al sito solo a ip selezionati

ErrorDocument 403 http://www.youdomain.com
Order deny,allow
Deny from all
Allow from 124.34.48.165
Allow from 102.54.68.123

8. Bloccarre accesso al file .htaccess

# secure htaccess file

order allow,deny
deny from all

9. Proteggere accesso a file specifici per server. Ad esempio evitare di far visualizzare il file default.jpg

# prevent access of a certain file

order allow,deny
deny from all

10. Disabilitare la visualizzazione dei files di una cartella

# disable directory browsing
Options All -Indexes

11. Settare la pagine di default. di solito č index.html

# serve alternate default index page
DirectoryIndex about.html

12. Proteggere con password directory o files.

# to protect a file

AuthType Basic
AuthName “Prompt”
AuthUserFile /home/path/.htpasswd
Require valid-user

# password-protect a directory
resides
AuthType basic
AuthName “This directory is protected”
AuthUserFile /home/path/.htpasswd
AuthGroupFile /dev/null
Require valid-user

13. Ridirezionare un vecchio dominio su uno nuovo

# redirect from old domain to new domain
RewriteEngine On
RewriteRule ^(.*)$ http://www.yourdomain.com/$1 [R=301,L]


Correlati

Leave a reply