.htacess stuff

Guide to .htaccess
Turning off directory listings
Blocking IP addresses
Custom error pages without Cpanel

BACK

 

 

 

 

 

 

 

Guide to .htaccess

You can find a very good guide to .htaccess here: http://javascriptkit.com/howto/htaccess.shtml
Back to Top

 

Turning off directory listings

So you don't want people seeing all the files you have in a directory when you don't have an index page there huh? No problem at all! The following line inside an .htaccess file will keep those directory listings from showing up:

Options -Indexes
Back to Top

 

Blocking IP addresses

If you need to block an IP address from accessing a directory on your site, place the following into an .htaccess file located in the directory you wish to block their access from:

Order Allow,Deny
Allow from all
Deny from 111.111.111.111

Replace 111.111.111.111 with the IP you wish to block.

If you need to block more than one ip:
Order Allow,Deny
Allow from all
Deny from 111.111.111.111
Deny from 222.222.222.222

or:
Order Allow,Deny
Allow from all
Deny from 111.111.111.111 222.222.222.222


If you wish to deny access to an entire block of IPs, only give a portion of the IP:
Order Allow,Deny
Allow from all
Deny from 111.111
Back to Top

 

Custom error pages without Cpanel

If you're looking to create custom error pages the old fashioned way (editing the .htaccess file yourself), look no further.

To do so you must first edit an .htaccess file in your public_html directory so that it has the following lines in it:
ErrorDocument 404 /myerrors/404.html
ErrorDocument 403 /myerrors/403.html
ErrorDocument 500 /myerrors/500.html


To explain what each part is we'll cut it up:

ErrorDocument - the command that tells apache that this is the error document to user for this directory and all directories under it unless a directory under it specifies otherwise.

404 (403 and 500) - The error code that states which error this document is to be called for.

/myerrors/404.html (403.html and 500.html) - the document that is to be used if this error should arise. In this case the error documents are located within the /public_html/myerrors/ directory. Please note that you need the / at the beginning so that apache (the web server) knows to start at /public_html/


With the above used document location, the url remains the same, but the error page is shown. If you wish to have it so the url changes to that of the error page then simply turn it into a url. The example below shows how to do this for the 404 (file not found) error:
ErrorDocument 404 http://www.yourdomain.com/myerrors/404.html


Should you notice that after doing this, your error page doesn't come up, check spelling, capitalization and the path or url of the error document to make sure it's correct. If it is, then try adding more content to the error page. Some browsers are set so that if there isn't enough content in the error page, they use their own default error page.
Back to Top

 

©2004 Solid Hosting. All rights reserved