Feed Sign in with OpenID OpenID

Simon Willison’s Weblog

Learning mod_rewrite

I think I’ve finally cracked mod_rewrite, thanks mainly to SitePoint. Key resources:

Nothing though can beat a good set of examples, and the URL Rewriting Guide by the module’s original author provides those in abundance.

This is Learning mod_rewrite by Simon Willison, posted on 29th August 2003.

View blog reactions

Next: On mod_python

Previous: Too much accessibility

4 comments

  1. 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 - #

  2. 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:tolower
    RewriteCond ${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 - #

  3. A good set of examples makes all the difference in the world. I recently used mod_rewrite to rewrite some URLs for the sake of Google indexing (my archived posts have query strings in their URLs which I've read Googlebot doesn't like). I didn't know a thing about mod_rewrite (still taking baby steps at this point) but it does seem like voodoo to me ;)

    MikeyC - 31st August 2003 00:48 - #

  4. Rewriting for search purposes is nice to have too.

    coda - 4th September 2003 11:00 - #

Comments are closed.

Previously hosted at http://simon.incutio.com/archive/2003/08/29/modRewrite

A django site