webbhelp Posted November 20, 2013 Share Posted November 20, 2013 Hi! I am using codeigniter framework, and what I am trying too do is to route the user to the right adress. I have the URL like this: www.site.se/en/webshop/method www.site.se/webshop/method and the problem is that the /en/ will not make any difference, because I am trying to bypass that with this: $route['([a-zA-Z]+)/(:any)'] = '$2'; So if there is anything with a-zA-Z then it will ignore it and just go with the rest of the url ($2). This doesn't work correctly. If I go to: www.site.se/en/webshop/ then it works, this too: www.site.se/webshop/ This also work: www.site.se/en/webshop/method BUT this doesn't work: www.site.se/webshop/method www.site.se/en/webshop/ - WORK www.site.se/webshop/ - WORK www.site.se/en/webshop/method - WORK www.site.se/webshop/method - DON'T WORK SO the problem is, if I don't have any language in the url, the method don't run. I hope you understand the problem and can help me, because I am stuck here, and I don't understand why this don't work, or what to try with... Thanks in Advance! Link to comment https://forums.phpfreaks.com/topic/284102-expression-where-a-z-or-nothing-beginner/ Share on other sites More sharing options...
AbraCadaver Posted November 20, 2013 Share Posted November 20, 2013 The + means there must be 1 or more. Try a * Link to comment https://forums.phpfreaks.com/topic/284102-expression-where-a-z-or-nothing-beginner/#findComment-1459219 Share on other sites More sharing options...
webbhelp Posted November 20, 2013 Author Share Posted November 20, 2013 Thanks for the reply. But unfortunately it didn't worked... The problem I can see is that if I remove the language from the url like: en/sv/dk or whatever it is $route['([a-zA-Z]*)/(:any)'] = '$2'; Then the regexp cannot match a-zA-Z before the / Right? Is there even any possible solution to this? The expression (in words) would be: If there is something before the / , the regexp is correct, but if not, then it should just ignore it or something. I am really stuck at this point Link to comment https://forums.phpfreaks.com/topic/284102-expression-where-a-z-or-nothing-beginner/#findComment-1459226 Share on other sites More sharing options...
requinix Posted November 20, 2013 Share Posted November 20, 2013 So make the [a-zA-Z] and the slash optional. $route['([a-zA-Z]+/)?(:any)'] = '$2'; Link to comment https://forums.phpfreaks.com/topic/284102-expression-where-a-z-or-nothing-beginner/#findComment-1459241 Share on other sites More sharing options...
webbhelp Posted November 20, 2013 Author Share Posted November 20, 2013 hmm it didn't worked :/ $route['([a-zA-Z]+/)?(:any)'] = '$2'; I used this your line of code and still this work: http://s/gbc/sv/webshop/web but not this: http://s/gbc/webshop/web I have another solution which is: require_once( BASEPATH .'database/DB'. EXT ); $db =& DB(); $query = $db->select('short')->get('language'); if($query->num_rows() > 0) { foreach($query->result() as $l) { $route[strtolower($l->short) .'/(:any)'] = '$1'; $route['('. strtolower($l->short) .')'] = 'webshop'; } } which is that is creates a route for every language there is. and if there is something else than a language in the url like sv is svkaosdka instead, then the application redirect the user to url.se/sv/webshop. This is an alternative solution I tried with, this works, but I thought I could do this with one route instead :/ Link to comment https://forums.phpfreaks.com/topic/284102-expression-where-a-z-or-nothing-beginner/#findComment-1459244 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.