Welcome Guest, Not a member yet? Register   Sign In
Excluding routes
#1

[eluser]Unknown[/eluser]
Hello,

We are having some problems with the routing part of codeigniter. We have some categories like this:
http://www.site.com/books/

These are rewrited to:
http://www.site.com/category/books

The route we use is:
$route['(:any)'] = '/category/index/$1';

But when we have a different page then a category page he also routes this like the category route. For example the contact page http://www.site.com/contact/ will also be routed to the category page.

Is there a way to exclude this from the route other then adding a bunch of routes for every page?

Regards,

Weccop
#2

[eluser]Raymondddd[/eluser]
Same problem here. Anyone know how to fix this?
#3

[eluser]bretticus[/eluser]
[quote author="Weccop" date="1269997143"]
The route we use is:
$route['(:any)'] = '/category/index/$1';

Is there a way to exclude this from the route other then adding a bunch of routes for every page?

[/quote]

You can do this with one route. You just have to add paths to it that you want to exclude:

Code:
$route['^(?!other_controller|assets).*'] = "/category/index/$0"; // all links unaccounted for will point at category controller.


EDIT:

Make sure you return 404 for any unmatched categories since pretty much everything that is not excluded will go through your category index method.
#4

[eluser]Raymondddd[/eluser]
Thanks for your solution @bretticus, works fantastic!
#5

[eluser]Raymondddd[/eluser]
@bretticus i also have a controller 'pages' with 2 functions: 'contact' and 'information'

If i use you're code (tried some variations) i can't access: url.com/pages/information (he's looking for a category)

If i use this route: $route['information'] = '/pages/information/'; i'm able to access my controller by using url.com/information.

So; my categories are working, but a lot of pages with 2 uri segments are acting like a category..
#6

[eluser]bretticus[/eluser]
Again, you must exclude any route that you do not want to be handled like categories:

Code:
$route['^(?!pages|assets).*'] = "/category/index/$0";

In this example, this $route entry will "disqualify" any URI route that begins with "pages" or "assets."

Also, please not that higher route entries take precedence over lower ones. From the manual:

Quote:Note: Routes will run in the order they are defined. Higher routes will always take precedence over lower ones.




Theme © iAndrew 2016 - Forum software by © MyBB