CodeIgniter Forums
url question - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: url question (/thread-1868.html)



url question - El Forum - 07-02-2007

[eluser]modano[/eluser]
Hi,

I wonder, how would i set up the url helper so that when www.domain.com/something/ is requested, and /something/ does not exist as a controller or anything, a default/specific controller would handle those requests?

thanks in advance,
modano


url question - El Forum - 07-02-2007

[eluser]zdknudsen[/eluser]
You can't use the URL helper for that. But one way of doing it would be adding the route

$route[':any/:any'] = "defaultcontrollername/defaultmethodname";

That would route any request to your defaultcontroller. But additionally you would have to add routes for your other controllers.

$route['news(.*)'] = "news$1";
$route['pies(.*)'] = "pies$1";
$route['forum(.*)'] = "forum$1";

And so forth. (By the way I haven't tested this, it's just from the top of my head, so it might not work).

EDIT: It's important that the :any/:any route is at the END of your routes config file, otherwise the defaultcontroller will always be called.


url question - El Forum - 07-02-2007

[eluser]modano[/eluser]
thanks a bunch zawk. as long as it is possible! im happy. if not, we are gonna have to dump CI and i dont want to do that Smile

will play around with what you suggested, thanks again!


url question - El Forum - 07-02-2007

[eluser]marcoss[/eluser]
[quote author="Zawk" date="1183403731"]
$route[':any/:any'] = "defaultcontrollere/defaultmethodname";
[/quote]

That's a really bad idea, you should never do that.

Instead you could modify the exception class to handle the errors your own way, try this implementation http://ellislab.com/forums/viewthread/54807/#269268.


url question - El Forum - 07-02-2007

[eluser]modano[/eluser]
ah, even better! thanks marcoss.

thanks both of you.
modano