Serving web pages

From ShawnReevesWiki
Revision as of 22:01, 7 February 2011 by Shawn (talk | contribs) (Examples)
Jump to navigationJump to search

Stopping spam and hackers

htaccess

An .htaccess file in a directory on a server tells the server how to handle specified requests or requests from specified internet addresses.

Examples of Apache directives

<Files .htaccess>
order allow,deny
deny from all
</Files>

Prevents anyone from reading the .htaccess file(s).

order allow,deny
deny from 59.92.4.185
deny from 66.225.201
deny from 69.80.96.0/20
allow from all

Prevents anyone from 59.92.4.185, addresses that start with 66.225.201, or addresses that match the first 20 bits of 69.80.96.0.

ErrorDocument 403 "Sorry, requests from your IP address are forbidden

Shows the phrase after " when access is denied to a page.

ErrorDocument 403 /errors/403.html

Replies with the 403.html file when access is denied to a page.

ErrorDocument 404 /errors/404.html

Replies with the 404.html file when the request can't be found.

order allow,deny 
allow from all

Put this in the folder where the 403 file is, and it allows even banned IPs access to the 403 error document (and any other files that are in that folder; better add the Files directive also).