Computers, Languages, Programming, Technology, Web Programming

Multilingual pretty URLs

There is more and more emphasis on pretty URLs these days. With things like Ruby on Rails around to easily support it and better knowledge and use of things like mod_rewrite the days of horrible query strings is going away (excluding of course the most used websites – search engines). But how do you make your multilingual website have pretty URLs?

My language learning app uses the Zend Framework and so uses pretty URLs by default. I need the interface available in many languages, but then the URLs should be pretty in a localized way.

For example, starting a new Finnish lesson uses the following:

/lesson/new/fi

That would be the new action of the lesson controller with an extra language code parameter of fi.

In German this should be something like:

/lektion/neu/fi

By default this would access the neu action of the lektion controller.

The “simple” solution would be to write lots of controllers that just delegate to the real one. Which is silly. Instead an extra layer has to be added to the routing process some sort of look-up table mapping localized URL fragments with “real” canonical ones. This should be fairly simple with Zend Framework (although I haven’t actually tried yet).

Just an important issue no-one seems to have brought up yet…

pretty URLs, Zend, Zend Framework, web frameworks, MVC

Advertisements

2 thoughts on “Multilingual pretty URLs

  1. How would you do multiple parameters in the URL?

    I don’t really mind query strings in URLs, it may look neater, but its not a big deal if the URLs a bit long is it?

    Like

  2. With Zend Framework (and Ruby on Rails) you set up “routes” which define possible URLs and the parameters they represent. The default route is:

    “:controller/:action”

    I also have:

    “lesson/:action/:language”

    You can still use query string parameters as well for complicated things – although most complicated things are submitted using a form and you’re better off using POST anyway.

    There are a couple of advantages besides looking prettier. Firstly it’s theoretically possible for someone to type the URLs to a page they want to get to straight away* and search engines treat them better.

    * It still does security checks as before. If you go straight to /lesson/new/fi without logging in it redirects you to the log in page.

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s