23 htaccess Hacks Everyone Should Know!

Discussion in 'General Programming Chat' started by The Scarlet Pimp, Jan 28, 2010.

  1. The Scarlet Pimp

    The Scarlet Pimp Senior Member

    Apr 2, 2008
    Likes Received:
    Chair moistener.
    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 23 .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. Or test these hacks inside of a sub-folder. If something goes kablooey, then simply discard the test folder.

    1. Prevent Hot Linking.

    2. Block All Requests From User Agents.

    3. Redirect Everyone Except Specified IPs.

    4. SEO Friendly 301 Redirects.

    5. Creating a Custom Error Page.

    6. Create an IP Banlist.

    7. Set Default Email Address For Server Admin.

    8. Disable Display of Download Request.

    9. Protect a Specific File.

    10. Compress Components With mod_deflate.

    11. Add Expires Headers.

    12. Setting the Default Page.

    13. Password Protect Your Directories and Files.

    14. Redirect an Old Domain to a New Domain.

    15. Force Caching.

    16. Compress Components By Enabling Gzip.

    17. Remove "category" from a URL.

    18. Disable Directory Browsing.

    19. Redirect WordPress Feeds to FeedBurner.

    20. Deny Comments from No Referrer Requests.

    21. Remove File Extension From URL.

    22. Remove www from URL.

    23. Add Trailing Slash to URL.

    • Thanks Thanks x 3