[Rails] Avoid parsing URL in Apache conf?

Ryan Platte ryan.platte at gmail.com
Fri Nov 19 08:22:29 GMT 2004


The thought has been bugging me since I was looking at the url_for
code a few days ago...

The knowledge of how URLs are set up for a Rails site is split between
the Apache conf and the Rails code. What if the mod_rewrite rules just
sent the entire path into dispatch.*, rather than parsing the
controller, action, and id parts? Then the same Rails code could be
responsible for translating to and from Rails params.

Something like (totally untested, don't actually use this):
RewriteRule ^([-_a-zA-Z0-9]+/.*)$ /dispatch.cgi?path=$1 [QSA, L]

Just the duplication of knowledge is smelly, but it seemed like the
UrlRewriter code was less sure of what it was doing than the rest of
the Rails code I've seen. I fixed a bug in UrlRewriter relating to the
"index" action being the default, and guess where that policy is also
expressed: mod_rewrite rules. Could be a coincidence, I suppose.

Seems to me like there's a missing abstraction here. Or am I all wet?

-- 
Ryan Platte


More information about the Rails mailing list