Thursday, February 04, 2010

20+ .htaccess Hacks Every Web Developer Should Know About

Apache's .htaccess(hypertext access) configuration file can be a very powerful tool in a web developer's toolkit if used properly. It can be found in the webroot of your server and can be easily edited using any text editor. In this article I'm going to show you 20 .htaccess hacks and how to use them.

Before I start with this article I'd like to start by saying that abusing the .htaccess file will hurt the performance of your website. The .htaccess file should only be used if you have no other way to achieve certain things.

Make sure to back up your current .htaccess file before applying any of the following hacks.

1. Prevent Hotlinking

Tired of people using your bandwidth by putting the images hosted on your server on their website? Add the following code at the bottom of your .htaccess file to prevent hotlinking.
view source
print?
1 Options +FollowSymlinks
2 #Protect against hotlinking
3 RewriteEngine On
4 RewriteCond %{HTTP_REFERER} !^$
5 RewriteCond %{HTTP_REFERER} !^http://(www.)?domainname.com/ [nc]
6 RewriteRule .*.(gif|jpg|png)$ http://domainname.com/img/stop_stealing_bandwidth.gif[nc]

NOTE: The following article explains better methods to "prevent" hotlinking:
Link building secrets by Maurizio Petrone


2. Block All Requests From User Agents
3. Redirect Everyone Except Specified IPs
4. SEO Friendly 301 Redirects
(more...)

Read more: DevMoose

Posted via email from jasper22's posterous