# Rewriting all requests to index.php

**URL:** <https://www.ruby-forum.com/t/rewriting-all-requests-to-index-php/191447>\
**Category:** NGINX\
**Created:** [July 12, 2010, 9:47pm UTC](https://www.ruby-forum.com/t/rewriting-all-requests-to-index-php/191447 "2010-07-12T21:47:23Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![astrochase](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/958977/32.png) [@astrochase](https://www.ruby-forum.com/u/astrochase)\
**Post date:** [July 12, 2010, 9:47pm UTC](https://www.ruby-forum.com/t/rewriting-all-requests-to-index-php/191447/1 "2010-07-12T21:47:23Z")

</div>

I’m new to Nginx. How do I rewrite all requests to index.php? So for  
example, if [http://www.example.com/some/path/](http://www.example.com/some/path/) is requested, I’d like  
[http://www.example.com/index.php](http://www.example.com/index.php) to transparently handle it.

How can I do this?

Posted at Nginx Forum:

> **[Rewriting all requests to index.php](https://forum.nginx.org/read.php?2,108022,108022#msg-108022)**
>
> I'm new to Nginx. How do I rewrite all requests to index.php? So for example, if http://www.example.com/some/path/ is requested, I'd like http://www.example.com/index.php to transparently handle it. How can I do this?

---

<div class="post-metadata">

**Author:** ![astrochase](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/958977/32.png) [@astrochase](https://www.ruby-forum.com/u/astrochase)\
**Post date:** [July 12, 2010, 9:55pm UTC](https://www.ruby-forum.com/t/rewriting-all-requests-to-index-php/191447/2 "2010-07-12T21:55:35Z")

</div>

12.07.10, 23:46, “astrochase” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> I’m new to Nginx. How do I rewrite all requests to index.php? So for  
> example, if [http://www.example.com/some/path/](http://www.example.com/some/path/) is requested, I’d like  
> [http://www.example.com/index.php](http://www.example.com/index.php) to transparently handle it.
> 
> How can I do this?

location / {  
root /path/to/www;  
include fastcgi\_params;  
fastcgi\_pass …;  
fastcgi\_param SCRIPT\_FILENAME /path/to/www/index.php;  
}

–  
br, Denis F. Latypoff.

---

<div class="post-metadata">

**Author:** ![astrochase](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/958977/32.png) [@astrochase](https://www.ruby-forum.com/u/astrochase)\
**Post date:** [July 12, 2010, 9:59pm UTC](https://www.ruby-forum.com/t/rewriting-all-requests-to-index-php/191447/3 "2010-07-12T21:59:06Z")

</div>

Got it! Thank you!

Posted at Nginx Forum:

> **[Re: Rewriting all requests to index.php](https://forum.nginx.org/read.php?2,108022,108026#msg-108026)**
>
> I'm new to Nginx. How do I rewrite all requests to index.php? So for example, if http://www.example.com/some/path/ is requested, I'd like http://www.example.com/index.php to transparently handle it. How can I do this?

---

<div class="post-metadata">

**Author:** ![astrochase](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/958977/32.png) [@astrochase](https://www.ruby-forum.com/u/astrochase)\
**Post date:** [July 13, 2010, 10:30am UTC](https://www.ruby-forum.com/t/rewriting-all-requests-to-index-php/191447/4 "2010-07-13T10:30:06Z")

</div>

You can use also the try\_files (  
[http://wiki.nginx.org/NginxCoreModule#try\_files](http://wiki.nginx.org/NginxCoreModule#try_files) ) approach:

location / {  
try\_files $uri $uri/ /index.php?$args;  
}

This way you can also have normal directories and static files and nginx  
will check first if they exist and if not then use the /index.php in the  
root folder.

rr
