Welcome Guest, Not a member yet? Register   Sign In
conditional routing (shorten url)
#9

(01-28-2019, 02:58 PM)kilishan Wrote: Here's one potential way to handle it, though it comes with a pretty big caveat:

- In your routes config file do a "catch-all" route as the very last route. That way any route not found or specified above that is sent to the controller/method of your choice.
- In that controller you'd have to parse the URL segments manually to determine what page to show based on your app's business logic.

The big caveat is that this means you MUST manually specify all other routes in the system, instead of relying on CI's automatic routing based on Controller/Method name in the URL.

This same type of setup could be used for the 404 Controller as Pertti said. Check the Reserved Routes section on the URI Routing page to see how to override the 404 action.

Hi, thank you for the tips, yeah I did that, I specify all the pages in my routes.php so it will have the URL that I intend (code below).

//////////////////////////////////
$route['about-us'] = 'home/display/about-us';
$route['blog'] = 'home/display/blog';
$route['testimonials'] = 'home/display/testimonials';

$route['car-towing'] = 'towing-services/display/car-towing';
$route['truck-towing'] = 'towing-services/display/truck-towing';
$route['motorbike-towing'] = 'towing-services/display/motorbike-towing';

///// There's more, but you got the point //////////

But the only problem is that I created a backend that can create a new page, so every time I create a new page I have to write the page-urlĀ in routes.php, it's not automatic Sad.

If anyone wondering why I'm using flat structure URL instead Silo structure URL, it's for SEO purposes.
Reply


Messages In This Thread
conditional routing (shorten url) - by acebay - 01-26-2019, 11:22 PM
RE: conditional routing (shorten url) - by Pertti - 01-27-2019, 12:49 PM
RE: conditional routing (shorten url) - by acebay - 01-27-2019, 02:11 PM
RE: conditional routing (shorten url) - by acebay - 01-27-2019, 02:00 PM
RE: conditional routing (shorten url) - by acebay - 01-28-2019, 02:10 PM
RE: conditional routing (shorten url) - by acebay - 01-28-2019, 05:56 PM



Theme © iAndrew 2016 - Forum software by © MyBB