Php and urls with /?xxx

Ahoi,

at the moment i use a “location .php {}” block for opening php-files
through fastcgi_pass. But what’s the right way for
calls like www.xxx.xxx/?xxx=xxx ?

For Wordpress-Urls like /index.php/xxx/
try_files $uri $uri/ /index.php?q=$request_uri;
works fine, but for /?

Thank you!

Posted at Nginx Forum:

On 18 Nov 2011 23h31 WET, [email protected] wrote:

Ahoi,

at the moment i use a “location .php {}” block for opening
php-files through fastcgi_pass. But what’s the right way for calls
like www.xxx.xxx/?xxx=xxx ?

For Wordpress-Urls like /index.php/xxx/
try_files $uri $uri/ /index.php?q=$request_uri;
works fine, but for /?

Try this:

    ## Regular PHP processing.
    location ~ ^(?<script>.+\.php)(?<path_info>.*)$ {
        include fastcgi.conf;
        ## The fastcgi_params must be redefined from the ones
        ## given in fastcgi.conf. No longer standard names
        ## but arbitrary: named patterns in regex.
        fastcgi_param SCRIPT_FILENAME $document_root$script;
        fastcgi_param SCRIPT_NAME $script;
        fastcgi_param PATH_INFO $path_info;
        ## Passing the request upstream to the FastCGI
        ## listener.
        fastcgi_pass phpcgi;
    }

Combined with:

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

Of course you have to fill in the details on static file handling,
blocking the readme.html file, etc.

— appa

António P. P. Almeida Wrote:

On 18 Nov 2011 23h31 WET, [email protected]
wrote:

Try this:

[…]

Thanks, but i alway get 500 error.

I’m using php-fpm with chroot-config, not sure what’s the right setting
for this.

For “location .php” i’m using:
fastcgi_param SCRIPT_FILENAME /htdocs$fastcgi_script_name;

Of course you have to fill in the details on
static file handling,
blocking the readme.html file, etc.

Is there really no easier way with the same behavior as apache?
/?xxx=xxx is alway /index.php?xxx=xxx :-/

Thanks

Posted at Nginx Forum:

On Sat, Nov 19, 2011 at 10:04 AM, Salem [email protected] wrote:

Is there really no easier way with the same behavior as apache?
/?xxx=xxx is alway /index.php?xxx=xxx :-/

It’s always like that unless you modify your fastcgi_params.


O< ascii ribbon campaign - stop html mail - www.asciiribbon.org

Thanks for the help.

Salem

Posted at Nginx Forum:

On Fri, Nov 18, 2011 at 06:31:51PM -0500, Salem wrote:

Hi there,

For Wordpress-Urls like /index.php/xxx/
try_files $uri $uri/ /index.php?q=$request_uri;
works fine, but for /?

The “location” goes from the / to just before the first ? or #.

You want this to be handled as if it were /index.php?xxx=xxx. So do
just that.

location = / {
fastcgi_pass unix:php.sock;
include fastcgi.conf;
fastcgi_param SCRIPT_FILENAME /htdocs/index.php;
}

The SCRIPT_FILENAME would normally be $document_root/index.php, but you
mention elsewhere that chroot is used. SCRIPT_FILENAME is “the name of
the file the php interpreter should load, from its perspective”.

(If you did fastcgi_pass to a different server, the filename on
that server would be what you would send. Which may be unrelated to
$document_root.)

Maybe just adding

index index.php;

within the server{} block instead, would be sufficient.

Good luck with it,

f

Francis D. [email protected]

On Sat, Nov 19, 2011 at 10:10 AM, Edho A. [email protected] wrote:

On Sat, Nov 19, 2011 at 10:04 AM, Salem [email protected] wrote:

Is there really no easier way with the same behavior as apache?
/?xxx=xxx is alway /index.php?xxx=xxx :-/

It’s always like that unless you modify your fastcgi_params.

Also you should remove index.php part from your permalink structure in
wordpress.


O< ascii ribbon campaign - stop html mail - www.asciiribbon.org