Julian Klewes

.htaccess cheat sheet

Tagged

Categorized
Dated 4 years ago






Times read: 372
Read today: 3
Read last: March 20, 2010

.htaccess cheat sheet

popup tail

Here is a simple cheatsheet for the .htaccess file:

Enable Directory Browsing

Options +Indexes
## block a few types of files from showing
IndexIgnore *.wmv *.mp4 *.aviDisable Directory Browsing

Options All -IndexesCustomize Error Messages

ErrorDocument 403 /forbidden.html
ErrorDocument 404 /notfound.html
ErrorDocument 500 /servererror.htmlGet SSI working with HTML/SHTML

AddType text/html .html
AddType text/html .shtml
AddHandler server-parsed .html
AddHandler server-parsed .shtml
# AddHandler server-parsed .htmChange Default Page (order is followed!)

DirectoryIndex myhome.htm index.htm index.php Block Users from accessing the site
order deny,allow
deny from 202.54.122.33
deny from 8.70.44.53
deny from .spammers.com
allow from all Allow only LAN usersorder deny,allow
deny from all
allow from 192.168.0.0/24Redirect Visitors to New Page/Directory

Redirect oldpage.html http://www.domainname.com/newpage.html
Redirect /olddir http://www.domainname.com/newdir/Block site from specific referrers

RewriteEngine on
RewriteCond %{HTTP_REFERER} site-to-block\.com [NC]
RewriteCond %{HTTP_REFERER} site-to-block-2\.com [NC]
RewriteRule .* – [F]Block Hot Linking/Bandwidth hogging

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?mydomain.com/.*$ [NC]
RewriteRule \.(gif|jpg)$ – [F]Want to show a ?Stealing is Bad? message too?

Add this below the Hot Link Blocking code:

RewriteRule \.(gif|jpg)$ http://www.mydomain.com/dontsteal.gif [R,L]Stop .htaccess (or any other file) from being viewed

order allow,deny
deny from all
Avoid the 500 Error

# Avoid 500 error by passing charset
AddDefaultCharset utf-8Grant CGI Access in a directory

Options +ExecCGI
AddHandler cgi-script cgi pl
# To enable all scripts in a directory use the following
# SetHandler cgi-scriptSave Bandwidth

# Only if you use PHP

php_value zlib.output_compression 16386
Password Protecting Directories

Use the .htaccess Password Generator and follow the brief instructions!

The CheckSpelling Directive

From Jens Meiert: CheckSpelling corrects simple spelling errors (for example, if someone forgets a letter or if any character is just wrong). Just add CheckSpelling On to your htaccess file.

The ContentDigest Directive

As the Apache core features documentation says: ?This directive enables the generation of Content-MD5 headers as defined in RFC1864 respectively RFC2068. The Content-MD5 header provides an end-to-end message integrity check (MIC) of the entity-body. A proxy or client may check this header for detecting accidental modification of the entity-body in transit.

Note that this can cause performance problems on your server since the message digest is computed on every request (the values are not cached). Content-MD5 is only sent for documents served by the core, and not by any module. For example, SSI documents, output from CGI scripts, and byte range responses do not have this header.?

To turn this on, just add Content Digest On.

Source: the net / google


People asked me to put up a donate button or something similar, so here it is: if you care to buy me a beer or Red Bull (I drink the Dutch equivalent called Spam Energy), feel free to donate, anything is appreciated!



h4x3d.com does not host any illegal content. Links/Files referred to are for educational purposes only.

Interact - Leave a comment

Engage in the conversion and leave a comment.
I would much love to hear from you. Please note however that comments are moderated by default. Advertising and rant is welcomed, yet often discarded...
See left/right for additional information













comment? jump to the form



archives | sitemap
contact | tos

Top

lorem

solarVPS.com - reliale enterprise hosting
you know the game, get in touch with me
3