views:

656

answers:

5

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").

+5  A: 

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

swilliams
+1  A: 

What's wrong with the manual?

Jim
Absolutely nothing! It seems I've been conditioned to assume the manual would be all but useless, but in this case it's actually extremely useful. Thanks for pointing that out!
Wilco
+2  A: 

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.

Kyle Burton
+3  A: 

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

Rui Vieira
+1  A: 

The Apache manual has lots of examples.

Jonathan Tran