# Understanding URL rewrite in sites-available

**URL:** <https://www.ruby-forum.com/t/understanding-url-rewrite-in-sites-available/195891>\
**Category:** NGINX\
**Created:** [October 2, 2010, 3:16am UTC](https://www.ruby-forum.com/t/understanding-url-rewrite-in-sites-available/195891 "2010-10-02T03:16:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ashrobertent](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/848f3c/32.png) [@ashrobertent](https://www.ruby-forum.com/u/ashrobertent)\
**Post date:** [October 2, 2010, 3:16am UTC](https://www.ruby-forum.com/t/understanding-url-rewrite-in-sites-available/195891/1 "2010-10-02T03:16:11Z")

</div>

Okay, I am using CodeIgniter which likes to use URL rewrites. I can turn  
it off, but don’t want to. I was able to deny direct access to index.php  
and at one point I was able to have the URL rewrite accept  
index.php/non-url/but/url-looking-data which it passed to index.php

My problem is that I have no idea what I am doing, I am just copying  
examples and thus I got one working, but when I tried the other I lost  
the first fix.

Let my start simple (for my sake) I see that one person said that all  
rewrites should be done at the server level instead of the location  
level… verification of this? Is that true?

What does !-e $request\_filename due?

Why is it better than try\_files (which I saw one person use) ?

Exactly what I am trying to do is hide index.php in the URL, but still  
send all url requests to index.php WITH the full url so that CodeIgniter  
can disect the url and get the paramaters for index.php to process.

Any help is appreciated. I will try to get better questions as I learn  
about this.

Posted at Nginx Forum:

> **[Understanding URL rewrite in sites-available](https://forum.nginx.org/read.php?2,136179,136179#msg-136179)**
>
> Okay, I am using CodeIgniter which likes to use URL rewrites. I can turn it off, but don't want to. I was able to deny direct access to index.php and at one point I was able to have the URL rewrite accept index.php/non-url/but/url-looking-data which...

---

<div class="post-metadata">

**Author:** ![ashrobertent](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/848f3c/32.png) [@ashrobertent](https://www.ruby-forum.com/u/ashrobertent)\
**Post date:** [October 2, 2010, 3:19am UTC](https://www.ruby-forum.com/t/understanding-url-rewrite-in-sites-available/195891/2 "2010-10-02T03:19:42Z")

</div>

Just to give background  
[CodeIgniter NGINX Rewrite Rules](http://farinspace.com/codeigniter-nginx-rewrite-rules/) seems to be  
exactly what I am trying to do, but it does not work. I get the  
index.php page when I go to  
[http://mywebroot/folder\_containing\_index.php/](http://mywebroot/folder_containing_index.php/)

but when I go to  
[http://mywebroot/folder\_containing\_index.php/url\_information\_to\_pass\_to\_index.php](http://mywebroot/folder_containing_index.php/url_information_to_pass_to_index.php)  
it does not send the url information to index.php

Posted at Nginx Forum:

> **[Re: Understanding URL rewrite in sites-available](https://forum.nginx.org/read.php?2,136179,136180#msg-136180)**
>
> Okay, I am using CodeIgniter which likes to use URL rewrites. I can turn it off, but don't want to. I was able to deny direct access to index.php and at one point I was able to have the URL rewrite accept index.php/non-url/but/url-looking-data which...

---

<div class="post-metadata">

**Author:** ![ashrobertent](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/848f3c/32.png) [@ashrobertent](https://www.ruby-forum.com/u/ashrobertent)\
**Post date:** [October 2, 2010, 3:46am UTC](https://www.ruby-forum.com/t/understanding-url-rewrite-in-sites-available/195891/3 "2010-10-02T03:46:02Z")

</div>

Even more confused… I commented out my entire default file except  
server {} and IT STILL LOADS the index.php file WITH the PHP fast  
CGI??!!! So basically my default file was doing NOTHING.

My current file:  
CAPS ARE MY PRIVATE VALUES with the EXEPCTION of SCRIPT\_FILENAME which  
appears to be a constant or variable

server {  
listen 90;

# server\_name SERVER

# access\_log PATH\_TO\_LOG

# error\_log PATH\_TO\_LOG

# root /var/www;

# index index.php index.html

# rewrite\_log on;

# if ($request\_ur ~\* ^(/welcome(/index)?|index(.php)/?$))

# {

# rewrite ^(.\*)$ / permanent;

# }

# if ($request\_uri ~\* index/?$)

# {

# rewrite ^/(.\*)/index?$ /$1 permanent;

# }

# if (!-d $request\_filename)

# {

# #some sites use \* and some use + what is the difference?

# rewrite ^/(.+)/$ /$1 permanent;

# }

# if (!-d $request\_uri ~\* ^/system)

# {

# rewrite ^/(.\*)$ /index.php?/$1 last;

# }

# if (!-e $request\_filename)

# {

# rewrite ^/$ index.php/;

# rewrite ^(/.\*)$ /index.php/$1 last;

# }

# error\_page 404 /index.php;

#location ~ .php$

# {

# fastcgi\_pass 127.0.0.1:90000;

# fastcgi\_index index.php;

# fastcgi\_param SCRIPT\_FILENAME DOCROOT$fastcgi\_script\_name;

# include fastcgi\_params;

# }

# location ~ /.ht

# {

# deny all;

# }

}

Posted at Nginx Forum:  
[http://forum.nginx.org/read.php?2,136179,136184#msg-136184](http://forum.nginx.org/read.php?2,136179,136184#msg-136184)
