# Php and urls with /?xxx

**URL:** <https://www.ruby-forum.com/t/php-and-urls-with-xxx/214030>\
**Category:** NGINX\
**Created:** [November 19, 2011, 12:32am UTC](https://www.ruby-forum.com/t/php-and-urls-with-xxx/214030 "2011-11-19T00:32:25Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [November 19, 2011, 12:32am UTC](https://www.ruby-forum.com/t/php-and-urls-with-xxx/214030/1 "2011-11-19T00:32:25Z")

</div>

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:

> **[php and urls with /?xxx](https://forum.nginx.org/read.php?2,218588,218588#msg-218588)**
>
> 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/...

---

<div class="post-metadata">

**Author:** ![Salem](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/8c91f0/32.png) [@Salem](https://www.ruby-forum.com/u/Salem)\
**Post date:** [November 19, 2011, 2:39am UTC](https://www.ruby-forum.com/t/php-and-urls-with-xxx/214030/2 "2011-11-19T02:39:01Z")

</div>

On 18 Nov 2011 23h31 WET, [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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

---

<div class="post-metadata">

**Author:** ![Salem](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/8c91f0/32.png) [@Salem](https://www.ruby-forum.com/u/Salem)\
**Post date:** [November 19, 2011, 4:05am UTC](https://www.ruby-forum.com/t/php-and-urls-with-xxx/214030/3 "2011-11-19T04:05:14Z")

</div>

## António P. P. Almeida Wrote:

> On 18 Nov 2011 23h31 WET, [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> 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:  
[http://forum.nginx.org/read.php?2,218588,218590#msg-218590](http://forum.nginx.org/read.php?2,218588,218590#msg-218590)

---

<div class="post-metadata">

**Author:** ![Salem](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/8c91f0/32.png) [@Salem](https://www.ruby-forum.com/u/Salem)\
**Post date:** [November 19, 2011, 4:11am UTC](https://www.ruby-forum.com/t/php-and-urls-with-xxx/214030/4 "2011-11-19T04:11:23Z")

</div>

On Sat, Nov 19, 2011 at 10:04 AM, Salem [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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](http://www.asciiribbon.org)

---

<div class="post-metadata">

**Author:** ![Salem](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/8c91f0/32.png) [@Salem](https://www.ruby-forum.com/u/Salem)\
**Post date:** [November 19, 2011, 2:57pm UTC](https://www.ruby-forum.com/t/php-and-urls-with-xxx/214030/5 "2011-11-19T14:57:02Z")

</div>

Thanks for the help.

Salem

Posted at Nginx Forum:

> **[Re: php and urls with /?xxx](https://forum.nginx.org/read.php?2,218588,218606#msg-218606)**
>
> 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/...

---

<div class="post-metadata">

**Author:** ![Salem](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/8c91f0/32.png) [@Salem](https://www.ruby-forum.com/u/Salem)\
**Post date:** [November 19, 2011, 4:47pm UTC](https://www.ruby-forum.com/t/php-and-urls-with-xxx/214030/6 "2011-11-19T16:47:46Z")

</div>

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. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![Salem](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/8c91f0/32.png) [@Salem](https://www.ruby-forum.com/u/Salem)\
**Post date:** [November 19, 2011, 4:14am UTC](https://www.ruby-forum.com/t/php-and-urls-with-xxx/214030/7 "2011-11-19T04:14:28Z")

</div>

On Sat, Nov 19, 2011 at 10:10 AM, Edho A. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> On Sat, Nov 19, 2011 at 10:04 AM, Salem [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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](http://www.asciiribbon.org)
