Welcome Guest, Not a member yet? Register   Sign In
Get rid of long urls?
#1

[eluser]Sven Delle[/eluser]
I have a Site Controller which I access like this:
Code:
www.domain.com/site/index/page_slug

As I use the page_slug to look up pages in the database. SEO friendly, right?

Now, I don't find the site/index part of the url very SEO friendly. How do I get rid of it (or at least the /index part of it)?

I've read all about routes in CodeIgniter, and to put it short: I don't get it!

How do I re-route my pages to the Site Controller and have the index function (the default) called passing the page_slug, as in:
Code:
www.domain.com/page_slug

This should of course only be for the Site Controller, as I have other controllers that need not be re-routed.

I can't seem to put the routes documentation to any use in my case. If I use site/(:all), well, ALL pages get re-routed in a loop of course.

Any thorough examples of how to do this (with thorough explanation)?
#2

[eluser]Sven Delle[/eluser]
I did this:
Code:
$route['(:any)'] = 'site/index/$1';

But this means that I have to specify ALL other functions I need to call in the routes config file as well.

Hmm. Well, for now ...
#3

[eluser]Sven Delle[/eluser]
Well, short joy there.

Now I can't get to my Admin Controller.

I can get to the admin login by:
Code:
$route['admin'] = 'admin/admin_login';

But all other admin requests I can't get to. I've tried all combinations of:
Code:
$route['admin/(:any)'] = 'admin/';
$route['admin/(:any)'] = 'admin/admin_login';
$route['admin/(:any)'] = 'admin/admin_login/$1';

None work.

Anyone know how to manage this?
#4

[eluser]drazik[/eluser]
You have to put the more specific rules before the less specific. So $route['(:any)'] must be the last rule
#5

[eluser]Sven Delle[/eluser]
Yeah, but when I'm logged in (sent to the admin/dashboard) it keeps redirecting me to the site/index as I'm requesting other controller. So I can't simply say:

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

Or similar.

So this seems to be kind of a challenge with a site containing dynamic data.

I can't see how else I could avoid having to specify A LOT (as anything other than the site/index routes) of routes. This is not maintainable in any way.

Has anyone got any solution examples of how to approach this - one controller for the basic pages (based on slug) and other specific controllers for other pages admin?
#6

[eluser]Sven Delle[/eluser]
This did the trick:

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

So I had to make sure that both 'admin' alone and 'admin/more' would be rerouted.

And as stated in the documentation:
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