Welcome Guest, Not a member yet? Register   Sign In
Routes regex problem
#1

[eluser]Armorfist[/eluser]
Hello,

I have the following route:

$route['^([a-z]+)\/([a-z]+)\/([a-z]+)\/(.+)\.html$'] = "$1/$2_$3/$4";

If I access the URI "/pages/front/general/index/something/something.html" it works fine. But if I access "/pages/front/general/index.html" it doesn't work, redirects to the default controller. I know something must be wrong with my regex, can someone help?

Thanks,
Frederico
#2

[eluser]Evil Wizard[/eluser]
from what you have put, it seems the regex is capturing 4 sub patterns separated by "/" which would suggest it generates a URI of "pages/front_general/index"
Code:
/pages/front/general/index/something/something.html
   |     |      |      |       |                  |> $ (end of string marker)
   |     |      |      |       |> included in sub pattern $4 <|
   |     |      |      |> $4 pattern match
   |     |      |> $3 pattern match
   |     |> $2 pattern match
   |> $1 pattern match
|> ^ (start of string marker)
according to the regex, both URI should be picked up and routed, is there anything else that is affecting the routes?
#3

[eluser]Armorfist[/eluser]
Thanks for the response. My full routes file is:

//Routes Admin
$route['admin'] = "users/admin_manage/index";
$route['^([a-z]+)\/([a-z]+)$'] = "$1/$2_manage";
$route['^([a-z]+)\/([a-z]+)\/([a-z]+)$'] = "$1/$2_$3";
$route['^([a-z]+)\/([a-z]+)\/([a-z]+)\/(.+)$'] = "$1/$2_$3/$4";

//Routes Front
$route['^([a-z]+)\/([a-z]+)\.html$'] = "$1/$2_general";
$route['^([a-z]+)\/([a-z]+)\/([a-z]+)\.html$'] = "$1/$2_$3";
$route['^([a-z]+)\/([a-z]+)\/([a-z]+)\/(.+)\.html$'] = "$1/$2_$3/$4";

Maybe I'm being a bit redundant, but I don't know much regex.
#4

[eluser]michalsn[/eluser]
Perhaps it will be helpful:

//Routes Admin
$route['admin'] = 'users/admin_manage/index';
$route['^([a-z]+)\/([a-z]+)$'] = '$1/$2_manage';
$route['^([a-z]+)\/([a-z]+)\/manage'] = '$1/$2_manage';
$route['^([a-z]+)\/([a-z]+)\/manage/(.+)$'] = '$1/$2_manage/$3';

//Routes Front
$route['^([a-z]+)\/([a-z]+)\.html$'] = '$1/$2_general';
$route['^([a-z]+)\/([a-z]+)\/([a-z]+)\.html$'] = '$1/$2_$3';
$route['^([a-z]+)\/([a-z]+)\/([a-z]+)\/(.+)\.html$'] = '$1/$2_$3/$4';
#5

[eluser]Armorfist[/eluser]
Thanks for the responses.
michalsn, I will optimize the regex as soon as I solve this problem. The code you suggested doesn't work in my case because not all controllers are named "something_manage".

Anyone has any more ideas?

Thanks,
Frederico
#6

[eluser]michalsn[/eluser]
First:
Code:
$route['^([a-z]+)\/([a-z]+)\/([a-z]+)\/(.+)\.html$'] = '$1/$2_$3/$4';
and then:
Code:
$route['^([a-z]+)\/([a-z]+)\/([a-z]+)\/(.+)$'] = '$1/$2_$3/$4';
#7

[eluser]Armorfist[/eluser]
yay it works! Thank you very much michalsn!!
Problem so simple... so much headache Wink




Theme © iAndrew 2016 - Forum software by © MyBB