|
Advanced HTML |
Basics of .htaccess.htaccess files are text files that you place in directories of your Apache web server to configure a variety of things such as custom web pages, redirects, password protection and allowing or dissalowing access to your site via IP address. Alghough .htaccess files are very common your ability to use them depends on 1) your site being hosted on a Apache server (which most are) and 2) your web host allowing you to use them. Not all hosts allow these files as they give access to some pretty powerful features but larger hosts such as 1&1 (where this site is hosted) do allow them. The file must be named '.htaccess' and can be in the root of any directory. .htaccess files will apply settings to the current directory and all sub-directories. However the .htaccess in the current directory will override any settings in any parent directories. If you find it is not possible to initially create a file called '.htaccess' in Windows then you can create it as 'htaccess' and rename it after you have uploaded it to your web server. Custom Error PagesOne of the most common usages for these files is to replace the default error pages. The most common error page being '404' when a file is not found. ErrorDocument 401 /401error.htm ErrorDocument 403 /403error.htm ErrorDocument 404 /404error.htm ErrorDocument 500 /500error.htm Permanently Redirecting People To Your New PageIf you move pages around on your site and you don't want to lose traffic from existing links to your old pages then you can use a .htaccess file to redirect people to your new pages. Here is part of a .htaccess file which I use to redirect people from my old domain to this one. redirect 301 /html/advancedhtml.htm http://www.advancedhtml.co.uk/advancedhtml.htm redirect 301 /html/animbuttons.htm http://www.advancedhtml.co.uk/animbuttons.htm redirect 301 /html/basictags.htm http://www.advancedhtml.co.uk/basictags.htm redirect 301 /html/colours.htm http://www.advancedhtml.co.uk/colours.htm Redirecting People Based on the Referring SiteI faced a problem where large numbers of MIDlet game sites were hosting my game 'Atomic'. Most of them had a link to my site however they had a link to the root domain rather than the main Atomic page. I used a .htaccess file to redirect people from these specific sites to the correct page. First is how to do it for a single site. This redirects any links from 'http://midlet.org' which are coming into my 'index.html' page to the correct 'http://www.neiljohan.com/java/atomic.html' page.
Next how to do the redirect for multiple sites. Note the 'OR' which says that the rule continues on the next line. The [NC] means that it is not case sensitive.
Password Protection using .htaccessSee my password protection using .htaccess page.
Copyright © 1997 - 2008 Hosted by 1&1
|