# Rewrite problem http://x.x.x.x/folder\_name/index.php/css/first.css

**URL:** <https://www.ruby-forum.com/t/rewrite-problem-http-x-x-x-x-folder-name-index-php-css-first-css/213627>\
**Category:** NGINX\
**Created:** [November 7, 2011, 5:18pm UTC](https://www.ruby-forum.com/t/rewrite-problem-http-x-x-x-x-folder-name-index-php-css-first-css/213627 "2011-11-07T17:18:01Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [November 7, 2011, 5:18pm UTC](https://www.ruby-forum.com/t/rewrite-problem-http-x-x-x-x-folder-name-index-php-css-first-css/213627/1 "2011-11-07T17:18:01Z")

</div>

Hello,  
I made test against lighttpd and ngninx is 50% faster…

So I tried to use it with my already made application. (postgres &  
php).  
After setting evrything I found the URL to be a problem.

Apache and lighttpd can use URL  
[http://x.x.x.x/folder\_name/index.php/css/first.css](http://x.x.x.x/folder_name/index.php/css/first.css) as  
[http://x.x.x.x/folder\_name/index.php](http://x.x.x.x/folder_name/index.php) with REQUEST\_URI part =  
“/css/first.css” - this is handle by PHP and processed along…

Nginx is trying to open index.php as folder an of course 404 is  
thrown…

I was trying to rewrite this URL but no success

my /etc/nginx/sites-available/default

```auto
...
server {
                listen 80;
# listen 443 ssl;
                server_name jakasnazwa.localhost;

                ssl off;
                ssl_certificate /etc/nginx/server.crt;
                ssl_certificate_key /etc/nginx/server.key;

                root /home/main-www;
                index index.php index.htm index.html;

                error_log /var/log/nginx/website.error_log notice;
                #rewrite_log on;

                location ~ .php$ {
                  fastcgi_pass 127.0.0.1:9000;
                  fastcgi_index index.php;
                  fastcgi_param SCRIPT_FILENAME
/home/main-www$fastcgi_script_name;
                  include fastcgi_params;
                }

                location / {
                  autoindex on;
                  if (-f $request_filename) {
                        break;
                  }

                  if (!-e $request_filename) {
                         rewrite ^(.*)/index.php/(.+)$ $1/index.php/$2
last;
                        break;
                  }
                }
       }
```

Of course rewrite don’t change anything (cut and paste, part of url in  
the same place) but I have no idea how to force nginx to fire php-fpm na  
index.php file passing everything what is after this as parameter?

Can you point me to some clues or solution?

PS I know that URL should look different, but application is ready, I  
don’t want to change it in this moment .

Regards  
Mikolaj

Posted at Nginx Forum:

> **[Rewrite problem http://x.x.x.x/folder\_name/index.php/css/first.css](https://forum.nginx.org/read.php?2,217923,217923#msg-217923)**
>
> Hello, I made test against lighttpd and ngninx is 50% faster... So I tried to use it with my already made application. (postgres & php). After setting evrything I found the URL to be a problem. Apache and lighttpd can use URL...

---

<div class="post-metadata">

**Author:** ![mikolajj](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/3ab097/32.png) [@mikolajj](https://www.ruby-forum.com/u/mikolajj)\
**Post date:** [November 7, 2011, 8:42pm UTC](https://www.ruby-forum.com/t/rewrite-problem-http-x-x-x-x-folder-name-index-php-css-first-css/213627/2 "2011-11-07T20:42:53Z")

</div>

On Mon, Nov 07, 2011 at 11:17:14AM -0500, mikolajj wrote:

Hi there,

> Apache and lighttpd can use URL  
> [http://x.x.x.x/folder\_name/index.php/css/first.css](http://x.x.x.x/folder_name/index.php/css/first.css) as  
> [http://x.x.x.x/folder\_name/index.php](http://x.x.x.x/folder_name/index.php) with REQUEST\_URI part =  
> “/css/first.css” - this is handle by PHP and processed along…
> 
> Nginx is trying to open index.php as folder an of course 404 is  
> thrown…

Yes, that’s how it is frequently configured by default.

You’ll want to configure it to match your application.

> ```
> location ~ .php$ {
> fastcgi_pass 127.0.0.1:9000;
> fastcgi_index index.php;
> fastcgi_param SCRIPT_FILENAME
> 
> ```
> 
> /home/main-www$fastcgi\_script\_name;  
> include fastcgi\_params;  
> }

That location matches urls that end in “php”. Your url is  
/folder\_name/index.php/css/first.css, which doesn’t end in php,  
so you’ll want to use some location setting that matches that url –  
perhaps “starts with /folder\_name/index.php/” will be best.

For testing, you could use “includes php”, which would be

location ~ php {}

but that is unlikely to be good for the live site.

Once you have the location definition correct, you’ll want to use  
fastcgi\_split\_path\_info

> **[GitHub - nginxinc/nginx-wiki: ARCHIVED -- Source for the now archived NGINX Wiki...](https://github.com/nginxinc/nginx-wiki)**
>
> ARCHIVED -- Source for the now archived NGINX Wiki section of https://www.nginx.com

and then you’ll probably want to set PATH\_INFO or REQUEST\_URI or  
whatever  
your application requires, like in the example there.

> Can you point me to some clues or solution?

Hopefully the above makes sense.

Either change your current “php” location to match all urls you want  
handled by php; or make a new one that matches this location.

And use fastcgi\_split\_path\_info.

And the debug log can be very useful if you get lost.

Good luck,

## f

Francis D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
