Jump to content

expression where a-z or nothing [Beginner]


webbhelp

Recommended Posts

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!

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

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 :/

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.