开发者

Complex Routing (Several Domains, Altering path) : overiding, a good option?

I have some no so easy routing design issues with rails 3.

We have a website translated in several languages. Some of this languages have a full domain support like :

example.com -> english
example.es -> spanish
example.fr -> french
exemple.de -> german
... (lot more)

But we have also :

example.com/zh-hans -> chinese
example.com/ru -> russian
... (lot more)

I am aware with the constrains feature (to matches? wi开发者_如何学运维th request.host) but I have a lot of problems figuring out how to make the routing system works well with the both type of urls.

Everything broke as soon as we have two different type of requests :

host:example.es path:/everything-else
host:example.com path:/LANG/everything-else

The only solution I figured out is to make a catch all routes match '*' => 'website#routing' and to monkey-patch all the path helper but I guess it's not the best to maintain in the future the application.

Any solutions ?


I'd suggest setting up your routes to consistently map everything to path /LANG/..., then using your web server to rewrite URLs for the language-specific domains. So for example with Apache, you could use something like this:

    RewriteEngine On

    RewriteCond %{SERVER_NAME} example.de
    RewriteCond %{REQUEST_URI} !^/de
    RewriteRule ^.*$     http://%{SERVER_NAME}/de%{REQUEST_URI} [R]

    RewriteCond %{SERVER_NAME} example.es
    RewriteCond %{REQUEST_URI} !^/es
    RewriteRule ^.*$     http://%{SERVER_NAME}/es%{REQUEST_URI} [R]

    # etc.

(I'm not sure the RewriteCond is actually correct - it's supposed to say "every request path that doesn't start with '/de', '/es' etc.)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜