Codeigniter route regex - matches any line except 'admin'

I would like to send any route that does not match the admin route to my event controller. This seems like a fairly common requirement, and a quick search throws all kinds of similar questions .

The solution, as I understand it, seems to use a negative expression in the regular expression. So my attempt looks like this:

$route['(?!admin).*'] = "event"; 

.. which is working. Well, sort of. It sends any non-admin request to my event controller, but I need to pass the actual string that was matched: therefore / my-new-event / is redirected to / event / my new event /

I tried:

 $route['(?!admin).*'] = "event/$0"; $route['(?!admin).*'] = "event/$1"; $route['(?!admin)(.*)'] = "event/$0"; $route['(?!admin)(.*)'] = "event/$1"; 

... and several other increasingly random and desperate permutations. All results on page 404.

What is the correct syntax for passing a matched string to a controller?

Thanks:)

+4
source share
1 answer

I do not think you can do "negative routing".

But since the routes have the order: "the routes will be executed in the order in which they are defined. Higher routes will always take precedence over lower ones." I will first make my administrator, and then something else.

If I assume that your admin path looks like "/ admin / ...", I would suggest:

 $route['admin/(:any)'] = "admincontroller/$1"; $route['(:any)'] = "event/$1"; 
+9
source

Source: https://habr.com/ru/post/1398206/


All Articles