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.
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
Link building secrets by Maurizio Petrone
