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

5 comments:

  1. I found this to be pretty useful: http://www.addedbytes.com/apache/url-rewriting-for-beginners/

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

    http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html

    but as a gentler introduction:

    http://www.workingwith.me.uk/articles/scripting/mod_rewrite

    ReplyDelete
  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.

    ReplyDelete
  4. What's wrong with the manual?

    ReplyDelete
  5. The Apache manual has lots of examples.


    URL Rewriting Guide
    URL Rewriting Guide - Advanced topics

    ReplyDelete