routes, urls and languages |
[eluser]webrix[/eluser]
Hi, I'm trying to write a multi language application, here my situation: - I have a database with the pages translated Code: CREATE TABLE IF NOT EXISTS `pages` ( - I have the URI Language library what I want to do is have url that look like this <host>/it/azienda/chi-siamo/4 <host>/en/company/who-we-are/3 I write a route like this Code: $route['it/azienda/(:any)/(:any)'] = "company/show/($2)"; but it return 404 what is the best way to handle my situation? thanks
[eluser]devastator[/eluser]
I use this http://maestric.com/doc/php/codeigniter_i18n
[eluser]mddd[/eluser]
You should really check in the server log to see what page it is trying to access but I'm guessing the problem is that you are putting brackets in the url. I think the route should be Code: $route['it/azienda/(:any)/(:any)'] = 'company/show/$2'; // so not ($2) at the end
[eluser]webrix[/eluser]
I have tried to put this route Code: $route['it/azienda/(:any)/(:any)'] = 'company/show/$2'; Code: DEBUG - 2010-05-31 09:25:03 --> Config Class Initialized what could it be?
[eluser]mddd[/eluser]
Okay, from the CodeIgniter log it seems that the system is looking for a controller called 'azienda'. So it seems the route is not working. What url are you requesting? Does it match your route? For instance if you ask for /azienda/../.. that will not work because it has to start with /it..
[eluser]webrix[/eluser]
I have installed i18n but the results seems the same routes Code: $route['default_controller'] = "home"; url requested Code: <hosto>/it/azienda/chi-siamo/2 logs Code: DEBUG - 2010-05-31 09:55:49 --> Config Class Initialized
[eluser]mddd[/eluser]
I think the problem is in this route: Code: $route['^it/(.+)$'] = "$1"; After the first match, the routing stops. So basically the system will just remove /it from the front and then try to run the controller. You should change the route so it only matches a call with 1 segment. Like so: Code: $route['^it/(:any)$'] = '$1'; (At least, I think ":any" will match anything but not a "/". In other words, ":any" will only match 1 segment, not multiple segments). Edit: I was wrong, ":any" is the same as ".*". So you will have to check yourself that you only have 1 segment: Code: $route['^it/([^/]+)$'] = '$1';
[eluser]webrix[/eluser]
ok Code: $route['it/azienda'] = 'company'; this seems to solve the problem now the urls should look like Code: <host>/it/azienda/chi-siamo/2 but it's not so simple to handle many urls and to switch language in the same page. In the database I have an url field that is "chi-siamo" or "who-we-are", what's the best way to handle URL dynamically?
[eluser]mddd[/eluser]
Do you really need to put the language in the url for every page? The numbers 2 or 3 in the url are probably the id's of your pages, correct? That means that you don't need to put the language in the url. From looking at /azienda/chi-siamo/2 the system can know that the language is Italian. You can see this because in your route, you are throwing away the 'it' part! So you can just forget about the /en or /it part here. Just use it where it is necessary! And not anywhere else.
[eluser]webrix[/eluser]
but the /en and /it is good per SEO so, all the italian website is under this dir... right? |
Welcome Guest, Not a member yet? Register Sign In |