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

How to make Phalcon include GET params in the Routing?!

Hello everyone!

I don't like that for Phalcon's Routing these urls are the same:

site.com/
site.com/?id=1

site.com/?params=1,2,3&p=1

I can not count on support of GET params in the Routing but I would like to set up a behaviour for these cases.

if this url site.com/?id=1 does not match any in the routing it should be redirected to 404 page.

This is NOT OK:

https://forum.phalcon.io**/?xxx=teen**

It can be indexed and displayed in Google Search Results.

So is it possible to include GET params in the Phalcon's Routing?

edited Feb '17

Hi, that's the seoman's worst nightmare, but it's true

edited Feb '17

Not possible because it's query parameter. Just change your routes to something like:

site.com/ GET
site.com/{id} GET
site.com/ POST?

Why not use get params in routing? But site.com/?id=1 indeed correctly matches site.com by the http design. It's the same address with just other query parameter and should be handled by same endpoint imho.

edited Feb '17

Not possible because it's query parameter. Just change your routes to something like:

site.com/ GET
site.com/{id} GET
site.com/ POST?

Why not use get params in routing? But site.com/?id=1 indeed correctly matches site.com by the http design. It's the same address with just other query parameter and should be handled by same endpoint imho.

What is this then?

$router->add(
    '/p/([a-zA-Z0-9\-]+)',
    [
        'controller' => 'news',
        'action'     => 'index',
        'url'   => 1
    ]
);

example.com/p/fresh-news === example.com/p/fresh-news?p=1

I really think fresh-news?p=1 does not match ([a-zA-Z0-9\-]+)

It matches it, because query string is ignored wheh handling route. It's query parameter only.

well first set it in the routes:

$router->add( '/p/([a-zA-Z0-9\-]+)',
    [
        'controller' => 'news',
        'action'        => 'index',
        'url'               => 1            // url can be changed to anything basicly
    ]
);

Getting in the controller:


$this->request->getQuery("url");

Yeah this is an odd request, ?xxx=123 is not a route item, it is an added parameter. Even Google's SEO talks about that it should be used for Filters, Paging, and other what nots that shouldn't be considered for SEO and indexing.