Learning mod_rewrite
I think I’ve finally cracked mod_rewrite, thanks mainly to SitePoint. Key resources:
- Apache Resources Collection
- mod_rewrite: A Beginner’s Guide to URL Rewriting
- mod_rewrite: No More Endless Loops!
- The official documentation
Nothing though can beat a good set of examples, and the URL Rewriting Guide by the module’s original author provides those in abundance.
Learning Mod Rewrite was an eye opener for me. Suddenly I actually understood that a URL did not necessarily have to correspond to a script on the server, but could be complete abstracted to represent what ever the heck I wanted.
And of course their is that cool introductory quote - "Despite the tons of examples and docs, mod_rewrite is voodoo. Damned cool voodoo, but still voodoo. ''
Daniel Von Fange - 29th August 2003 13:26 - #
Geting complex Mod Rewrite tricks to work is one of my favorite things. One of the few computer things that still seems like magic to me.
I have a WebDAV enabled staging subdomain where I do I all of my client work. But I wanted each clients work to be it's own subdomain so all of their hrefs will match up just like they will on the live site. So I set up *.staging.mintchaos.com as a wildcard subdomain and used the following rewrite rule to make any clientx.staging.mintchaos.com pull from staging.mintchaos.com/clientx
RewriteEngine on RewriteMap lowercase int:tolowerRewriteCond ${lowercase:%{SERVER_NAME}} ^([a-z-]+)\.staging\.mintchaos\.com$
RewriteRule ^(.*) /home/mintch/www/staging/%1/$1
It's darned fun.
Xian - 29th August 2003 22:19 - #
MikeyC - 31st August 2003 00:48 - #
coda - 4th September 2003 11:00 - #