In this tutorial you will find out all sorts of stuff about the .htaccess file. This is a server configuration file in wich you can edit your server configuration. I.E: Make your own error pages! Your own custom made 404 error page.
A .htaccess file is used to set your webserver to your hands. It will all become clear later on in the tutorial.
Will my host support it?
That is a very good question. And the most difficult question to answer. Your host must host your website on a Apache webserver. That is because the only webserver that supports .htaccess files is the most used server world wide: Apache.
If you are not realy sure if your webhost runs this server you should call them or send an email with your question if they support .htaccess files.
How to make a .htaccess file?
Putting in the code is easy as pie. But saving the file may cause some problems.
The filename is .htaccess, but actually it has no name, it's just a 8 letter file extension.
To make a .htaccess file, open notepad and put in the code you want (will be treated later on) and click file-->save as. Now name the file ".htaccess", that includes the quotes, and save the file.
Now upload this to your webserver and your done!
Error numbers and their meanings
302 - Redirect
400 - Bad Request
401 - Authorization Required
402 - Payment Required
403 - Forbidden
404 - File Not Found
405 - Method Not Allowed
406 - Not Acceptable
407 - Proxy Authentication Required
408 - Request Time Out
409 - Conflict
410 - Gone
411 - Length Required
412 - Precondition Failed
413 - Request Entity Too Large
414 - Request-URI Too Large
415 - Unsupported Media Type
500 - Internal Server Error
501 - Method Not Implemented
502 - Bad Gateway
503 - Service Temporarily Unavailible
504 - Gateway Timeout
505 - HTTP Version Not Supported
Making Custom Error Pages
When you want to make custom error pages for a certain errornumber you can set that up in your .htaccess file.
Put in this code:
| Code: |
| ErrorDocument 404 /404.html |
First always put in ErrorDocument at the beginning of the line.
Then put in a space, then put in the errornumber, then put in the path to your custom error page.
Always use a forward slash at the beginning of the path.
Directory Indexes
Sometimes, for one reason or another, you will have no index file in your directory. This will, of course, mean that if someone types the directory name into their browser, a full listing of all the files in that directory will be shown. This could be a security risk for your site.
To prevent this (without creating lots of new 'index' files, you can enter a command into your .htaccess file to stop the directory list from being shown:
| Code: |
| Options -Indexes |
IP Banning
You may want to block a user with a specific IP Address from entering your website. You can put in the following code in your .htaccess file to do so.
| Code: |
| order allow,deny deny from 120.56.7.8 deny from 124.5.66.12 deny from 64.40.10.1 allow from all |
Ofcourse you will have to change those IP addresses.
You can also ban IP Ranges/Blocks:
| Code: |
| order allow,deny deny from 120.0.0 allow from all |
PHP in .html files
PHP is a interactive scripting language. You can only place PHP code in .php files. Do you want to start working with PHP and don't want to change all your file extensions from .html to .php? Then put in this code in your .htaccess file:
| Code: |
| AddType application/x-httpd-php .php .htm .html |
Be sure your webhost supports PHP first before you do this.
Redirecting
Redirecting means forwarding. When you automaticly want to redirect a directory to a certain website add this to your .htaccess file:
| Code: |
| Redirect /olddirectory http://directory-you-want-to-forward-to.com/directory |
Replace olddirectory with the directory you want to be forwarded to a certain address. Replace the URL with the address you want the old directory forwarded to.
Directory Indexes
You don't want index.html to be your starting page but you want portal.php to be your starting page? Enter this in your .htaccess file:
| Code: |
| DirectoryIndex portal.php |
Replace portal.php with your own file name and you are done.
Password Protection
There is a very easy generator for that:
http://www.tools.dynamicdrive.com/password/
Post your comment
Comments (1 posted)
-
Posted by SEO-Dragon,great great great , its all i can say :D













CyberNews


