Jump to content

expression where a-z or nothing [Beginner]


webbhelp
Go to solution Solved by 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!

Edited by webbhelp
Link to comment
Share on other sites

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
Share on other sites

  • Solution

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.