Welcome Guest, Not a member yet? Register   Sign In
regular expression for URI routing
#1

[eluser]Tomas Sundvall[/eluser]
Hello!

I'm trying to create an route that makes all urlConfused call a certain function in a certain controller.

So if you for example go to
http://mypage/page1, http://mypage/start/index/page1 will "be used".

I've got it to work easily with:
Code:
//$route[':any'] = "start/index";

The problem is that there is one exception, and that is when you go to
http://mypage/admin, then I want the admin controller to "be used".

I tried to create a regular expression that made everything go to "start/index" except if you wrote admin, but I wasn't successfull.

Does anyone know how to do that?

/Tomas
#2

[eluser]mddd[/eluser]
Just make a route for admin and put it before the other one.
CI will use the first route that matches your url.
#3

[eluser]CI_avatar[/eluser]
Tom, route can work only for same controller routing. route can't route from $route[':any'] = "start/index" (controller to other controller).
or $route['controller1/:any'] = "other_controller/index";
#4

[eluser]mddd[/eluser]
Avatar, where did you get that idea? That is totally incorrect.
#5

[eluser]CI_avatar[/eluser]
I made a mistake. sorry
#6

[eluser]CI_avatar[/eluser]
@Tom, dont use $route[':any'] = "go to somewhere"; because it has highest routing priority.
#7

[eluser]Tomas Sundvall[/eluser]
Thanks for your answers!

I tried to write:
$route[’admin’] = 'admin/login'
$route[’:any’] = 'start/index'

So that dosen't work since $route[’:any’] has the highest routing priority? So then the problem must be solved using a regular expression that routs anything except 'admin' (case insensitive) to 'start/index'?

I tried with:
$route['^[^admin].*'] = "start/index";

It worked a little bit better. But the problem was that evrything that starts with admin is not sent to "start/index". So if I for example write http://mypage/administration, then I'm not being routed to "start/index".

I don't really know how to rewrite it so it only not sends admin to "start/index".

Does anyone have an idea of how to do this? :-).

/Tomas
#8

[eluser]mddd[/eluser]
No. The routes are tried IN ORDER.
So if the 'admin' route is before the 'any' route, it should work just fine!
If the two routes as you have written them here don't work, there is something else wrong.
#9

[eluser]bretticus[/eluser]
You need to be explicit in your routes! They will do exactly what you tell them to do. If you want anything with admin as the controller segment redirected to the admin controller, where you have an "override all routes" route below, you must explicitly define it (and any others that might occur later on)...

Code:
$route['admin/(:any)'] = 'admin/$1';
$route[':any'] = 'start/index';




Theme © iAndrew 2016 - Forum software by © MyBB