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

htaccess adds ?_url=/ when no trailing slashes provided

Hello,

I read a lot of discussions about routing but I couldn't find someone with the same problem I'm facing.

We have routes poiting to autogenerated apidoc, which goes to public/apidoc/ (with index.html, css folder, img folder etc)

in Bootstrap, I declared the route like this :

    $router->add(
        "/apidoc",
        [
            'namespace' => "Project\\Index\\Controllers",
            'module' => 'index',
            'controller' => 'index',
            'action' => 'apidoc'
        ]
    );

and in my action :

/**
 * Action to render the view of the auto-generated doc page
 * @param string $folder
 */
public function apidocAction () : void
{
    $this->view->setViewsDir(PUBLIC_PATH . '/apidoc');
}

If I want to access the page, it works with https://www.mywebsite.fr/apidoc/

But if I write down https://www.mywebsite.fr/apidoc, the url is rewritten like this :

https://www.mywebsite.fr/apidoc/?_url=/apidoc

It works, the doc is displayed but the url is ugly and not convenient...

I tried modifying htaccess in all ways and I'm out of ideas.

The htaccess files are like this :

public/.htaccess

AddDefaultCharset UTF-8

<IfModule mod_rewrite.c>
     RewriteEngine On
     RewriteCond   %{REQUEST_FILENAME} !-f
     RewriteRule   ^((?s).*)$ index.php?_url=/$1 [QSA,L]
</IfModule>

/.htaccess

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteRule ^$ public/ [L]
    RewriteRule (.*) public/$1 [L]
</IfModule>

Thanks for the help, I've been using Phalcon for 3 years now and I never faced the problem before, maybe the way we point public files with setViewsDir is wrong, I'm open to other solutions of course.



2.0k

Found out why... it seems to be happening when we have a phalcon route that is equal to a public route. It adds the strange suffix ?_url=

In the end, I removed the phalcon route, to access my doc via the url : https://www.mywebsite.fr/apidoc/index.html

Has someone a way to access index.html via the urls https://www.mywebsite.fr/apidoc and https://www.mywebsite.fr/apidoc/ with an .htaccess rule ? I tried many combination but can't find the right one.

Thanks