Welcome! Log In Create A New Profile

Advanced

Re: Requests ending with / (slash) are returning 404

April 07, 2010 05:06AM
On Wed, Apr 07, 2010 at 06:58:19PM +1000, Leonardo Crespo wrote:

> Wow, very elegant Igor. Thank you, it works beautifully.
>
> Could you help with the last bit?
>
> I'd like to return 404 if the user tries /foo/page.php instead of /foo/page

location ~ \.php$ {
return 404;
}

> I read the nginx wiki for try_files
> (http://wiki.nginx.org/NginxHttpCoreModule#try_files) and coudn't find
> the advanced syntax that you've given me to use (and that it works
> great). Is there any other nginx info resource that you could share?

This wiki article is invalid, it should be fixed.
Here is one example of try_files usage:
http://nginx.org/en/docs/http/converting_rewrite_rules.html#converting_mongrel_rules

> Best,
>
> Leonardo.
>
> 2010/4/7 Igor Sysoev <igor@sysoev.ru>:
> > 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/
> >
> > _______________________________________________
> > nginx mailing list
> > nginx@nginx.org
> > http://nginx.org/mailman/listinfo/nginx
> >
>
> _______________________________________________
> nginx mailing list
> nginx@nginx.org
> http://nginx.org/mailman/listinfo/nginx

--
Igor Sysoev
http://sysoev.ru/en/

_______________________________________________
nginx mailing list
nginx@nginx.org
http://nginx.org/mailman/listinfo/nginx
Subject Author Posted

Requests ending with / (slash) are returning 404

leocrespo April 07, 2010 04:28AM

Re: Requests ending with / (slash) are returning 404

Igor Sysoev April 07, 2010 04:44AM

Re: Requests ending with / (slash) are returning 404

edogawaconan April 07, 2010 04:54AM

Re: Requests ending with / (slash) are returning 404

Igor Sysoev April 07, 2010 05:02AM

Re: Requests ending with / (slash) are returning 404

leocrespo April 07, 2010 05:02AM

Re: Requests ending with / (slash) are returning 404

Igor Sysoev April 07, 2010 05:06AM

Re: Requests ending with / (slash) are returning 404

edogawaconan April 07, 2010 05:08AM

Re: Requests ending with / (slash) are returning 404

leocrespo April 07, 2010 05:14AM

Re: Requests ending with / (slash) are returning 404

edogawaconan April 07, 2010 05:20AM

Re: Requests ending with / (slash) are returning 404

leocrespo April 07, 2010 05:30AM

Re: Requests ending with / (slash) are returning 404

leocrespo April 07, 2010 05:34AM

Re: Requests ending with / (slash) are returning 404

Igor Sysoev April 07, 2010 05:50AM

Re: Requests ending with / (slash) are returning 404

Igor Sysoev April 07, 2010 05:48AM

Re: Requests ending with / (slash) are returning 404

leocrespo April 07, 2010 06:28AM

Re: Requests ending with / (slash) are returning 404

leocrespo April 07, 2010 06:44AM

Re: Requests ending with / (slash) are returning 404

edogawaconan April 07, 2010 06:50AM

Re: Requests ending with / (slash) are returning 404

leocrespo April 07, 2010 07:10AM

Re: Requests ending with / (slash) are returning 404

Igor Sysoev April 07, 2010 05:24AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 175
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