We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Route everything to index.php

Hi,

I'm building a CMS of sorts, with an undefined number of unique URLs. I'd like all URLs to be redirected to my Index controller. What do I need to make my route in order for this to work?

I've tried:

'/*'    =>  [   'controller'    =>  'index',
                'action'        =>  'index']

But that doesn't work. I know I could probably just route all 404 traffic to index, but that seems dirty.

That didn't work, but this regex did: /(.*)

I'm confused as to why I didn't try that before posting.

The URLs aren't intended to point to a controller or action - they are simply URLs like you'd see on any reasonably complex website - merely referring to an address of a page. So I can't break up the URL in the route - all I want is the full string I can then process in code. My regex routes all traffic to the index controller, and $_SERVER['REQUEST_URI'] contains the requested URI - in your example "/Title/edit".

In my particular case, the url musn't be 2 "words" long. It could be 3, 4 10, 20, and the path is entirely up to the users. There's essentially no restriction to the format of the URLs, so trying to make them fit into even a semi-rigid structure of controller/action. In your originally suggested solution, I would still have to break up the "article" parameter just like I'm doing with the full URL now.

Nonetheless, I do appreciate you taking the time for this discussion.

Sign in is done through Shibboleth - before Phalcon even gets touched.

But there will be special pages - true - I imagine they'll be declared in later rules like you suggest.

That's a good idea.