Welcome! Log In Create A New Profile

Advanced

PHP plus rewrite--how to?

Posted by androo 
PHP plus rewrite--how to?
October 09, 2009 02:04PM
I have a PHP application that runs just fine, but when I try to set up a short-URL rewrite it breaks. Here's the original stanza for the virtual server, with long URLs:

server {
listen 80;
server_name example.com;
access_log /path/to/log main;
location / {
root /path/to/example.com;
index index.html index.php;
}
location ~ \.(html|php) {
include /path/to/fastcgi.conf;
root /path/to/example.com;
fastcgi_pass 127.0.0.1:12345;
fastcgi_index index.php;
}
}

Now, I have an application (Gallery 3) in a subdirectory of example.com, so the URLs are e.g. http://www.example.com/gallery3/... and the files are at /path/to/example.com/gallery3/... The rewrite, of course, should apply only to documents in the gallery3 directory. I tried adding the following stanza above location~ \.(html|php):

location ~ /gallery3/ {
if (!-e $request_filename) {
rewrite ^(.*)$ index.php?kohana_uri=$1 last;
}
}

I've tried a bunch of variations on this, but no luck. All generate 404 errors or "No input file specified." What am I missing?

Many thanks,
androo
Re: PHP plus rewrite--how to?
October 10, 2009 07:49PM
Okay, I figured it out. For the record:

1. The rewrite stanza has to go after, not before, the php stanza.

2. Also, with G3 at /home/gallery3/, the rewrite stanza has to look like this:

location ~ /gallery3/ {
root /home;
index index.html index.php;
if (!-e $request_filename) {
rewrite ^/gallery3/(.*)$ /gallery3/index.php?kohana_uri=$1 last;
}
}

Hope that helps anyone else who may be wondering.
Re: PHP plus rewrite--how to?
October 13, 2009 10:36AM
You may find it more efficient with a "try_files" directive.

[code]
location ~ /gallery3/ {
root /home;
index index.html index.php;
try_files $uri $uri/ /gallery3/index.php?kohana_uri=$1;
}
[/code]

--
Jim Ohlstein
Re: PHP plus rewrite--how to?
October 15, 2009 06:54PM
Interesting idea. Is try_files less resource-intensive? Just curious why it would be more efficient.
Re: PHP plus rewrite--how to?
October 15, 2009 07:50PM
androo Wrote:
-------------------------------------------------------
> Interesting idea. Is try_files less
> resource-intensive?

Yes

Just curious why it would be
> more efficient.

It has to do with how requests are parsed. Igor is [b]ADAMANT[/b] about it (he really hates using "if's" in these situations). In order to understand exactly I suspect that I would need to be an experienced C programmer - or even a passable one, something I am not.

--
Jim Ohlstein
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 234
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready