Requests ending with / (slash) are returning 404
Igor Sysoev
igor at sysoev.ru
Wed Apr 7 12:40:08 MSD 2010
On Wed, Apr 07, 2010 at 06:24:36PM +1000, Leonardo Crespo wrote:
> Hi all!
>
> Can anyone with more experience give me hand? I've spent the last 4
> hours trying many options and none of them worked, so I decided to ask
> for help.
>
> What i'm trying to do:
> /foo/bar/page served by /foo/bar/page.php
>
> This one is working fine, as I can remove the.php extension from the
> request and the page loads o (www.domain.com/page shows the content of
> www.domain.com/page.php)
>
> However, requests ending in a / (slash) are not working
> /foo/bar/ served by /foo/bar/index.php
> (www.domain.com/portal/ should show the content of
> www.domain.com/portal/index.php)
>
> I can't get this to work properly no matter what. I've tried if
> conditions for the $request_uri, different location groups, flags for
> the rewrite option and sadly i can't get it to work.
>
> Can anyone with more experience give me a hand? Here's my conf file (snippet)
>
>
> ============
> server
> {
> listen 80;
> server_name www.domain.com.au;
> access_log /home/public_html/domain.com.au/log/access.log;
> error_log /home/public_html/domain.com.au/log/error.log error;
> root /home/public_html/domain.com.au/public;
>
> #file size
> client_max_body_size 100m;
>
> location = /
> {
> root /home/public_html/domain.com.au/public/;
> index index.php index.html;
> }
>
> location /
> {
> root /home/public_html/domain.com.au/public/;
> index index.php index.html;
> ####### ---- allows /foo/bar/page to /foo/bar/page.php
> rewrite ^([^.?]+)$ $request_uri.php last;
> }
>
> # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
> location ~ \.php$
> {
> fastcgi_pass 127.0.0.1:9000;
> fastcgi_intercept_errors on;
> fastcgi_index index.php;
> include /usr/local/nginx/conf/fastcgi_params;
> fastcgi_param SCRIPT_FILENAME
> /home/public_html/domain.com.au/public/$fastcgi_script_name;
> }
> }
> ============
location / {
try_files $uri $uri.php $uri/ =404;
fastcgi_pass 127.0.0.1:9000;
fastcgi_intercept_errors on;
fastcgi_index index.php;
include /usr/local/nginx/conf/fastcgi_params;
fastcgi_param SCRIPT_FILENAME
/home/public_html/domain.com.au/public/$fastcgi_script_name;
}
or
location / {
try_files $uri $uri.php ${uri}index.php =404;
fastcgi_pass 127.0.0.1:9000;
fastcgi_intercept_errors on;
include /usr/local/nginx/conf/fastcgi_params;
fastcgi_param SCRIPT_FILENAME
/home/public_html/domain.com.au/public/$fastcgi_script_name;
}
--
Igor Sysoev
http://sysoev.ru/en/
More information about the nginx
mailing list