Friday, June 8, 2012

Apache Mod-Rewrite Primers?

I am wondering what primers/guides/tutorials/etc. are out there for learning to rewrite URLs using Apache/.htaccess? Where is a good place to start?

My primary interest is learning how to point certain directories to others, and how to use portions of a URL as parameters to a script (i.e. "/some/subdirs/like/this" => "script.php?a=some&b=subdirs&c=like&d=this").

Source: Tips4all


  1. I found this to be pretty useful:

  2. I would go straight to the horse's mouth:

    but as a gentler introduction:

  3. The Apache Documentation site has a good introduction to using mod_rewrite.

    It covers how the directive works and has quite a few examples, eg:

    RewriteRule ^/games.* /usr/local/games/web
    RewriteRule ^/product/(.*)/view$ /var/web/productdb/$1

    It coveres everything from the basic sytanx for changing the URI (which is what you seemed to be asking about) as well as using regular expressions, conditions and responding with redirects.

    The apache documents have always been useful to me. O'Reilly's Apache: The Definitive Guide is also a good physical resource.

  4. What's wrong with the manual?

  5. The Apache manual has lots of examples.

    URL Rewriting Guide
    URL Rewriting Guide - Advanced topics