views:

267

answers:

3

I've recently been improving my skills with web programming to follow the saner and more maintainable MVC style of coding. However, one thing which I used to do with my "roll your own" framework was flexible dynamic routing based around mod_rewrite. This appears to be a sore issue with things like cakephp, zend, etc.. and its causing me some headaches by trying to duplicate the functionality which I had.

In a roll your own context, you could do something like the following:

<custom htaccess rules before>
RewriteRule    ^([A-Za-z0-9-/]+)$    index.php?q=$1   [NC,L]

which rewrites all matched urls to an arbitrary script that handles the url, parses the combinations of "/abc-123/abc-456/controller-value" etc to any list of pages or actions, functions etc that can be set up from a database table, hardcoded, bla bla.. The custom rules before can pass through matched requests for files that exist for resources on the server, or setup admin routing etc.

However, once the MVC url policy kicks in, it is extremely hard to override this behaviour with something that hides the application logic from the outside world. I never really understood why anyone would want to expose function names to a user, and this is my real bugbear. It seems unnecessary and an imposition too far, from usability and security perspectives.

So - the question is this, how to approach a rewritten, translatable and friendly url policy while maintaining a solid MVC foundation to the application?

Requisites:

  • No application logic exposed
  • Translatable URLs (i18n)
  • Dynamic and ability to add, remove, edit urls or pages without touching application code

Fun times! :D

Example URLs:

/en/news/story-title
/pt/noticias/titulo

where the urls retrieve localised content based on language string passed.

+1  A: 

MVC is just an architectural pattern which has nothing to do with URL structure. Using a custom routing layer will not break MVC by any means. If centralized routing is OK for you, then, for example, you can have a config file which maps URL patterns (regexes or some kind of simplified syntax) to controller actions.

Ignas R
Yeah, but the question is, if such a framework exists with this already in place, or if its always going to be a case of implementing it from scratch. The translated URLs are a big deal for me.
danp
Also, in general the MVC structure is always reflected in the URL, which I find annoying, so the two things are very closely related.
danp
After a bit of research, it appears that a custom routing layer is the only real way forward, but its a little bit crazy having this routing layer on top of another routing layer, just to control a URL.
danp
A: 

you can create a controller to manipulate your routes file , using file handling

Ish Kumar
A: 

I believe (although I'm not sure) Akelos supports Translatable URLs.

Alix Axel