Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Internationalized user visible URLs (all on one server):

http://example.us/example/path
http://example.de/beispiel/pfad

The URL paths should translate internally to (for further processing with mod_rewrite):

/en_US/example/path
/de_DE/beispiel/pfad

What's a good method to add a culture prefix once to a path?

share|improve this question

1 Answer 1

What's a good method to add a culture prefix once to a path?

The answer is: not at all. If you don't want your users to know that your structure is like that, then don't show it to them. That means, when you get a request for .com.br, you internally check the HTTP_HOST, and assign a variable to your script, which can then execute based on the language.

To be perfectly honest, I think mod_rewrite is a waste of time for this. If your site is written in any half-decent scripting language, you can have your script lookup the HTTP_HOST in a database, which matches to a language, and you can continue from there. mod_rewrite (and thus most .htaccess directives) don't really scale dynamically: what if, when they hit the .com version of your website, you want to lookup their IP and redirect them to the most appropriate suffix based on their approximate location? You'll have a tough time doing that with just mod_rewrite.

share|improve this answer
    
There is an existing Symfony app which expects paths with the prefix. It then rewrites them further. Really I don't want to change that. –  feklee Oct 30 '12 at 23:01
    
Just updated the question; forgot to mention that paths are internationalized. The prefix is needed to avoid ambiguities (some words have different meanings in different cultures). –  feklee Oct 31 '12 at 7:26
    
Well, in the end I did pretty much what you suggested: I revamped the internal routing of the application. Now the router of the application determines the culture from the domain name. By the way, I noticed that you wrote: "If you don't want your users to know that your structure is like that, then don't show it to them". I think there is a misunderstanding: My original idea of using mod_rewrite was exactly to not reveal the culture prefix. Only the application should see it. In the past, it was user visible, thus redundant as culture is already encoded in the domain name. –  feklee Nov 1 '12 at 21:18

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.