CodeIgniter - How to redirect a controller with a different name?

I have installed an authentication module named bit_auth in my Igniter code. I have a controller for this module named "bit_auth", so when calling functions on my controller, my urls will be like this:

http://(mydomain.com)/bit_auth/
http://(mydomain.com)/bit_auth/edit_user/1
http://(mydomain.com)/bit_auth/activate/7b60a33408a9611d78ade9b3fba6efd4fa9eb0a9

      

Now I want to direct my controller bit_auth

to be called from http://(mydomain.com)/auth/...

.
I have defined these routes in my " config/routes.php

":

$route['auth/(:any)'] = "bit_auth/$1";
$route['auth'] = "bit_auth";

      

It works fine when I use: http: // (mydomain.com) / auth /
but shows 404 page not found when opening links like:
http: // (mydomain.com) / auth / edit_user / 1
http: // (mydomain.com) / auth / activate / 7b60a33408a9611d78ade9b3fba6efd4fa9eb0a9

What am I doing wrong?

+3


source to share


2 answers


After searching and researching, I saw somewhere where I was using a different syntax for routing in CodeIgniter that used regex directly and not using the codeigniter patterns described such as or in its help. I just replaced with in mine and now it works fine. (:any)

(:num)

(:any)

(.+)

config/routes.php

$route['auth/(.+)'] = "bit_auth/$1";
$route['auth'] = "bit_auth";

      



Because in CodeIgniter (:any)

, and (:num)

are not included/

, and they are aliases for the regular expression pattern ([^\/]+)

and (\d+)

, therefore, if you want to combine the rest of the link, including any number /

, you can use the manual regular expression pattern (.+)

, which includes /

in its template and will run for the rest of the url.

+1


source


Since you are using more parameters than in the route, you will need to do this:

$route['auth/(:any)/(:num)'] = "bit_auth/$1/$2";

      



Hope this helps!

+4


source







All Articles