Web Hosting Talk







View Full Version : Web Developers Must Use It: .htaccess


Flipe.NET
12-05-2004, 04:37 PM
I visit a lot of sites everyday, and in most of them wont use this important tool.

.htaccess is a simple and powerfull tool that can be used to redirect error pages, deny users by ip, password protection and more...
Here is a simple example code:

DirectoryIndex index.php

ErrorDocument 404 http://site.com/erro.php?id=404
ErrorDocument 502 http://site.com/erro.php?id=502
ErrorDocument 503 http://site.com/erro.php?id=503
ErrorDocument 501 http://site.com/erro.php?id=501


.htaccess is the file extension. It is not file.htaccess or something.htaccess, it is simply named .htaccess
Remember always to upload the file as ASCII.

Directory Index is the file that ll be called when you open a a folder page. You can put only one like
DirectoryIndex index.php
or more like
DirectoryIndex index.php index.html index.shtml

For me the more important tool is Error Pages.
To use it, just put:
ErrorDocument ERROR PAGE
The PAGE is the document error default page.
The error is the number of the possible error:
Here the possibles Errors:


Successful Client Requests
200 OK
201 Created
202 Accepted
203 Non-Authorative Information
204 No Content
205 Reset Content
206 Partial Content
Client Request Redirected
300 Multiple Choices
301 Moved Permanently
302 Moved Temporarily
303 See Other
304 Not Modified
305 Use Proxy
Client Request Errors
400 Bad Request
401 Authorization Required
402 Payment Required (not used yet)
403 Forbidden
404 Not Found
405 Method Not Allowed
406 Not Acceptable (encoding)
407 Proxy Authentication Required
408 Request Timed Out
409 Conflicting Request
410 Gone
411 Content Length Required
412 Precondition Failed
413 Request Entity Too Long
414 Request URI Too Long
415 Unsupported Media Type
Server Errors
500 Internal Server Error
501 Not Implemented
502 Bad Gateway
503 Service Unavailable
504 Gateway Timeout
505 HTTP Version Not Supported


You can only upload a .htaccess for your server in root www folder that error pages ll be up and all.
EX: You set up a error page 404 for site.com/404.htm
When someone try to open any file or folder that is under www.site.com/ will be redirected to www.site.com/404.htm
Like www.site.com/ada/ada/da
Like www.site.com/adadadada.php

I hope this helps all.

Its a simple tutuorial, just for those that dont know it.

More help open:
http://www.freewebmasterhelp.com/tutorials/htaccess/
http://www.javascriptkit.com/howto/htaccess.shtml

sololo
12-06-2004, 09:00 AM
Hey Flipe. Thats good job man. Actually i was creating this last night .htaccess in the www helping a guy whose entire Parent Directory was listed
Yeah you can also use .htaccess to protect
stuff like Jpegs and Gifs or zips that you do not want people to browse through (while the plumbers fix the main drainage)

IndexIgnore *
if you put in an htaccess file in your images directory, nothing in that directory will be listed.

IndexIgnore *.gif *.jpg
This would return lists of all files not ending in .gifs or .jpegs,
Probably this saved me trips to index manager.

sololo
12-06-2004, 09:07 AM
Index.html is a 404.

Flipe.NET
12-06-2004, 09:29 AM
.htaccess have many other functions too.
Directory listing can be used in Cp too.
Deny Ip, and others functions maybe dont.
So i resolve to said it.
Regards

sololo
12-07-2004, 11:25 AM
True that.

darkforce
12-08-2004, 11:08 AM
thanks for the tips my friend i shall try this.

Flipe.NET
12-08-2004, 10:14 PM
is that what we here for.
.htaccess have many utilities.
:)

sololo
12-09-2004, 02:04 PM
Flipe its absurd how one go thru great length of creating all the scripts and stuff, you test and everything works except for those images. For the third time i forgot linux is case sensitive, but then, a whole Jpeg cd comes with an extension .JPEG. Before i finally noticed the ext were in upper case, ive stressed for hours checking the "conveyer belt Image slide script" and changing htaccess.
Why does this kodak saves image ext as Upper Case default, damn it you kojak!

Flipe.NET
12-09-2004, 07:06 PM
Sorry, im from BRasil, and do not understand nothing you said!
You complicated too much.
Tnkz

sololo
12-11-2004, 05:47 AM
I suppose, no kidding!

webolocity
02-19-2005, 10:20 PM
good post.

this will help users to learn what .htaccess is since allot are not familiar with this. Also, since cpanel has "password protected directories" whereas it will automatically create the .htaccess page, this may help some troubleshoot errors, by not being intimidated to open these files and look inside.

:)