Well before I begin, here’s a little window into what htaccess (hypertext access) is all about.
An htaccess file is a simple ASCII file, such as you would create through a text editor like NotePad. Many people seem to have some confusion over the naming convention for the file, so let me get that out of the way. ‘.htacess’ is simply a file extension with no file name at all. [dot] by default makes the files hidden on almost every web servers and operating systems. In simple words, they are simple text files where you can put server directives similar to “httpd.conf” or a “php.ini” file. But the real difference is unlike these master directive files, htaccess powers you to apply directives to the directories in which htaccess resides and the subdirectories within.
Now let us come to the point for which you are here – the groovy things:
1. Password Protection
Adding password protection to your directories is a simple 2 step process.
i. Add appropriate directives to the htaccess file in the directory you wish to protect. Every subdirectory and file will be protected within.
1 2 3 4 | AuthName "Section Name" //it’s the directory name you wish to protect AuthType Basic AuthUserFile /full/path/to/.htpasswd // absolute path of the .htpasswd file Require valid-user |
ii. Create a .htpasswd file that contains usernames and passwords. The username password pairs must be added in the format “username:password”, where password is encrypted format of the password. You can encrypt the password using one of the premade scripts available on the web or write your own. There is a good username/password service at the KxS site http://www.kxs.net/support/htaccess_pw.html which will allow you to enter the user name and password and will output it in the correct format.
.
2. Save Bandwidth with .htaccess
You can save some bucks by putting in the code below into your htaccess file. It enables the PHP’s built-in zlib compression module. It will squeeze your bandwidth usage approximately to half or even more.
Note: if you run phpsuexec, you’ll need to put php directives in a local “php.ini” file and not in htaccess.
1 2 3 | <ifModule mod_php4.c> php_value zlib.output_compression 16386 </ifModule> |
.
3. Deny or Allow users from a particular network/IP Address:
Is there a pesky person bugging you? Stalking your site, htaccess powers you to block him/her. You can deny access based upon IP address or an IP block. The above blocks access to the site from xxx.xxx.xxx.xxx, and from any sub-domain under the IP block xxx.xxx.xxx.
1 2 3 4 5 6 7 8 9 | * order allow,deny
deny from xxx.xxx.xxx.xxx // to deny from particular IP Address
deny from xxx.xxx.xxx. // to deny from set of IP Addresses
allow from all
* deny from all // to deny requests from all ip addresses |
.
4. Custom Error Pages
htaccess allows you to have your own, personal error pages to show up when the server responds with an error code. And henceforth, give your site a more professional outlook in unlikely event of error. By doing this you give yourself a good chance to retain your almost-lost visitor. This is how you can do this. Al you need to know is the error number.
ErrorDocument errornumber /file.html
e.g.
1 2 3 4 | ErrorDocument 401/errors/401.php ErrorDocument 403/errors /403.php ErrorDocument 404/errors /404.php ErrorDocument 500/errors /500.php |
.
5. STOP Directory index from listing
Many times you might have faced the situation that you do not have index file in your directory. In such case all the files just get listed in the browser that can lead to security risks. With htaccess you can plug this.
All you have to do is type in Options -Indexes into your htaccess file and no more directory listings.
.
That’s it!
Cheers!!


Comments
awesome guide, i always had issues with directory listing available to general public when i wanted it to stay out of reach of peaky eyes.
i compiled a .htaccess from this guide and plug the holes on my flash games website.
thanks for sharing!
Great article! There is another important thing that I use frequently: the 301 redirection from the address without www to be with www or viceversa. This is very important for SEO, especially site ranking:
RewriteEngine on
# 301 redirect to domain to ‘www.’
RewriteCond %{HTTP_HOST} ^website-name.com$ [NC]
RewriteRule ^(.*)$ http://www.website-name.com/$1 [R=301,L]
Cool! Thanks for sharing
Intresting tips. Thanks
Another thing is #6 rewriting your url into search engine friendly format.
wow, that’ s great. i would go for it.
Another great thing with .htaccess is to stop people stealing your bandwidth, when they hotlink your images.
Thanks for this list.
neat tricks for htaccess – thanks!
I recently came across your article and have been reading along. I want to express my admiration of your writing skill and ability to make readers read from the beginning to the end. I would like to read newer posts and to share my thoughts with you.
Very good article. Quite informative and well written. I enjoyed reading it and it made me think.
I enjoyed reading this article. I will come back soon to read it again.
Thanks for htaccess update. I didn’t know much about this tools activities and certainly bookmarking you now.
Wow this takes me back. Like your blog design too.
Good article and right to the point. I am not sure if this is really the best place to ask but do you folks have any ideea where to get some professional writers? Thanks
great tricks for htaccess
Great article! There is another important thing that I use frequently: the 301 redirection from the address without www to be with www or viceversa. This is very important for SEO, especially site ranking:
It’s my first time to post a reply, thanks for your sharing.
Informations like this I always prefer to collect. I always open your post with great wish.
That’s a wonderful stuff you shared. great work.
Thanks for such a great post and the review, I am totally impressed! Keep stuff like this coming.
I am actually not too familiar with this topic but I do prefer to take a look at weblogs for layout ideas and interesting topics. You truly expanded upon a topic that I normally do not care a lot about and produced it very exciting. This is a awesome website that I’ll consider be aware of. I already bookmarked it for long term reference. Cheers
“Hey – nice blog. Just checking out some blogs, appears a pretty nice system you happen to be employing. I am presently using WordPress for a couple of my blogs but I’m not pleased with it thus far. I am searching to change 1 of them more than to a platform identical to yours (BlogEngine) as a trial operate. Something in certain you’d suggest about it?”
I really do not normally reply to blogposts but I will on this situation. Wow
yeah,I just thought you might want to know that your blog is messed up when you view it on my iphone. I?m not sure if it has something to do with my phone?s browser or your website? just saying…
As a Newbie, I am always searching online for articles that can help me. Thank you Wow! Thank you! I always wanted to write in my site something like that. Can I take part of your post to my blog?
Its a well writen and comprehensive post you made. I am sure you get many visitors that compliment you on your posts. After reading this post I got some very unique information which are really very helpful for anyone. This is a post having some crucial information. I wish that in future such posting should go on.
Hi… that was great stuff.. I really like reading on this subject Could you tell me more on that… I love to explore
I like your post 3) I’ll surely be peeping into it again soon! ;>
Howdy, I found your blog in a new directory of weblogs. I dont know how your web site came up, must have been a typo, Your web site looks really good. Also i wanted to take your rss feed but i couldn’t. Don’t know why!!? Best wishes, Azalee.
Have you ever considered placing more videos to your web site posts to keep the audience more entertained? I mean I just read through the entire article of yours and it was quite very good but since I’m more of a visual learner,I found that to be more useful well let me know how it turns out! Regards, Mai.
some truly grand work on behalf of the owner of this web site, dead outstanding content material.
I have read, understood, after the problem!
thank you for this, this is some really interesting stuff
I comply with the comment above Great blog post btw
I agree on the commenter fantastic article a