Enrutamiento de URL de CodeIgniter: URL compatible con SEO

I've created a new route for my site:

$route['default_controller'] = "welcome";

$route['(:any)'] = "welcome/index/$1";

$route['404_override'] = '';

And this works fine in my site when URL is like this:

http://mydomain.com/first-article

http://mydomain.com/second-article

*my controller is just welcome.php

pero

i also have a controller for the admin and the URL for the admin is:

http://mydomain.com/admin

What will I add to the routes file to ignore the /admin and other controllers inside the admin?

preguntado el 08 de noviembre de 11 a las 13:11

2 Respuestas

Puede reemplazar el welcome/index/$1 route with:

$route['^(?!admin).*'] = "welcome/index/$1";

This basically says, that if a URI that does no start with "admin" should route to the welcome/index method and pass the contents to the index method. Otherwise, handle normal routing with admin being the controller.

respondido 08 nov., 11:18

thanks for the reply and it works!..but what if i want to add one more rule let say: if a URI does not start with "admin" and "users" it should route to the welcome/index method..how would i do this? - scoohh

Just add it in the routes separated with the pipe character: $route['^(?!admin|users).*'] = "welcome/index/$1"; -- you can add as many as you need. - swatkins

Abre application/config/router.php y cambiar el

$route['404_override'] = '';

a

$route['404_override'] = 'router/index';

You can use all controllers as the normal way.

When you try to use a controller that is not exists, you should route it to a 404 controller.

Create a controller named router.php as a controller structured for CodeIgniter.

En los índice método en el interior router.php, query for related sef url and do required operations. All requests that routes to an undefined controller will be handled by router/index method. Others will be redirected to related controller as usual.

You might want to use header codes to point that related page is not 404.

Respondido el 28 de junio de 17 a las 17:06

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.