Softpedia
 

NEWS CATEGORIES:



NEWS ARCHIVE >>
SOFTPEDIA REVIEWS >>
MEET THE EDITORS >>
Home > News > Webmaster > Tips and Tricks

August 30th, 2007, 14:14 GMT · By Adrian Placinta

.htaccess commands

SHARE:

Adjust text size:



Enlarge picture
.htaccess (Hypertext Access) is the default name of Apache's directory-level configuration file. .htaccess is used to provide security restrictions for a certain directory. The .htaccess file is often accompanied by a .htpasswd file which stores valid usernames and their passwords. With .htaccess you can customize
error responses. You can do that changing the page that is shown when a server-side error occurs. Also, you can rewrite URLs. Various server-side PHP scripts use .htaccess to rewrite URLs to shorter ones.

Customizing error messages is easier than you think. Define the your custom pages in .htaccess using for example ErrorDocument 401 /authorization.html and upload them in www directory. The usual error codes are: 400(Bad Request), 401(Authorization Required), 402(Payment Required), 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), 500(Internal Server Error), 501(Not Implemented), 502(Bad Gateway), 503(Service Unavailable), 504(Gateway Timeout) and 505(HTTP Version Not Supported).

If you don't have an index file on your website and you want to prevent users from accessing it and to list all your files from that directory, add the following command to .htaccess: Options -Indexes. Also, you can restrict access to your website for a certain IP addresses using deny and allow commands. You can block an ip address this way: deny from 192.168.0.20. Also you can block a range of ip addresses specifying only 1 or 2 group of numbers. To allow access to an ip address, add the following command to .htaccess: allow from 192.168.0.20.

Another thing you can do with .htaccess is redirecting requests to certain files: Redirect /location/from/root/file.ext http://www.softpedia.com/new/file/location.xyz. Also you can redirect directories from a website to another: Redirect /softpedia http://www.softpedia.com/softpedia
FILED UNDER:
htaccess
Apache
restrict

TELL US WHAT YOU THINK:

2,291 hits · Link to this article · Print article · Send to friend · Subscribe to news

MUST-READ RELATED ARTICLES:


Hosting Providers Requiring Clients to BLOCK Googlebot!

Tips to Improve Joomla Performance

Yahoo Introduced Backlinks Button

READER COMMENTS:



No user comments yet.
Be the first to express your opinion!
Copyright © 2001-2012 Softpedia. Contact/Tip us at

WindowsGamesDriversMacLinuxScriptsMobileHandheldNews

SUBMIT PROGRAM   |   ADVERTISE   |   GET HELP   |   SEND US FEEDBACK   |   RSS FEEDS   |   UPDATE YOUR SOFTWARE   |   ROMANIAN FORUM