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

URI_SOURCE_SERVER_REQUEST_URI seems not working

Hi $router->setUriSource(Router::URI_SOURCE_SERVER_REQUEST_URI); seems to not working

I did try_files $uri $uri/ /index.php?$uri&$args;

i tried this too try_files $uri $uri/ /index.php;



368

Do you have option (Options All) under directory at virtual host ? And if u use rewrite rules in htacces needs to be

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

Igor, i am using nginx and wrote nginx rules. And i don't want to use $_GET['_url'], I wanted to use $_SERVER['REQUEST_URI'], i have got problem with this kind of setup :) Look at https://docs.phalcon.io/en/latest/reference/routing.html#uri-sources



368

Ok i've tested, it works on 1.0.0 Required rules on apache <IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ index.php [QSA,L] </IfModule>

DI EXAMPLE

//Specify routes for modules
$di->set('router', function () use($routes) {

    $router = new \Phalcon\Mvc\Router();
    $router->setUriSource(\Phalcon\Mvc\Router::URI_SOURCE_SERVER_REQUEST_URI);

    return $router;

});

For me it doesn't work. I recompiled Phalcon tried $router = new \Phalcon\Mvc\Router(false); and $router = new \Phalcon\Mvc\Router();



368

Can you paste your di ?



98.9k

Hi, are you using the following instructions: https://docs.phalcon.io/en/latest/reference/nginx.html

Could you print your $_SERVER var?

Hi, I am using modified Basic configuration, and it works:

server {
    server_name localhost.dev;

    root /var/www/phalcon/public;
    index index.php index.html index.htm;

    location / {
        try_files $uri $uri/ /index.php?_url=$uri&$args;
    }

    location ~ \.php$ {
            try_files $uri =404;
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_index index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include fastcgi_params;
    }
}

but i wanted to use $router->setUriSource(Router::URI_SOURCE_SERVER_REQUEST_URI); and

    .......
    location / {
        try_files $uri $uri/ /index.php;
    }
    .........

I don't like to setup nginx rewrite rules like that with $_GET['_url '], i think that framework should handle this job itself by $_SERVER['REQUEST_URI'] Is there any working example tiny working bootstrap index file which works?



98.9k

I tested with the following conf and it's working

https://gist.github.com/phalcon/5296737

Hi, thank you for quick response.

I did trivial mistake from my side ... sometimes tiny typo makes big waste of time :) When i tried to disable View::LEVEL_MAIN_LAYOUT my website hangs, after some minutes i discovered that it sould be \Phalcon\Mvc\View::LEVEL_MAIN_LAYOUT

I have just did the same mistake at Router :) It shouldn't be $router->setUriSource(Router::URI_SOURCE_SERVER_REQUEST_URI); It should be $router->setUriSource(\Phalcon\Mvc\Router::URI_SOURCE_SERVER_REQUEST_URI); // this is working :)

Nginx server configuration should use try_files instead of conditional if. I advise to change configuration in documentation to this way:

server {
    server_name localhost.dev;

    root /var/www/phalcon/public;
    index index.php index.html index.htm;

    location / {
        try_files $uri $uri/ /index.php?_url=$uri&$args;
    }

    location ~ \.php$ {
            try_files $uri =404;
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_index index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include fastcgi_params;
    }
}

and with $router->setUriSource(\Phalcon\Mvc\Router::URI_SOURCE_SERVER_REQUEST_URI); to this

server {
    server_name localhost.dev;

    root /var/www/phalcon/public;
    index index.php index.html index.htm;

    location / {
        try_files $uri $uri/ /index.php;
    }

    location ~ \.php$ {
            try_files $uri =404;
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_index index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include fastcgi_params;
    }
}