Welcome! Log In Create A New Profile

Advanced

Re: Rewrite before regex location

Joyce Babu
May 04, 2016 06:54PM
Hi Francis,

Thank you for the response.

Possibly using "location ^~ /test/" would work?
>
> http://nginx.org/r/location
>
> You may want to rewrite to /test.php (with the leading slash), though.
>
> Although, better might be to just fastcgi_pass directly, rather than
> rewriting.
>
> Something like (untested)
>
> location ^~ /test/ {
> fastcgi_param SCRIPT_FILENAME $document_root/test.php;
> fastcgi_param QUERY_STRING q=$uri;
> include fastcgi_params;
> fastcgi_pass 127.0.0.1:9000;
> }
>
> although you would want to change the QUERY_STRING line to match what
> you need; and you may need to switch the position of the "include",
> depending on how your fastcgi server handles repeated params.
>

There are over 300 rewrites under 54 location blocks.

I tried using ^~ as you suggested. Now the rewrite is working correctly,
but the files are not executed. The request is returning the actual PHP
source file, not the HTML generated by executing the script.



> > location ~ [^/]\.php(/|$) {
> > fastcgi_split_path_info ^(.+?\.php)(/.*)$;
> >
> > set $fastcgi_script_name_custom $fastcgi_script_name;
> > if (!-f $document_root$fastcgi_script_name) {
> > set $fastcgi_script_name_custom "/cms/index.php";
> > }
>
> I suspect that it should be possible to do what you want to do there,
> with a "try_files". But I do not know the details.
>

There is a CMS engine which will intercept all unmatched requests and check
the database to see if there is an article with that URI. Some times it has
to match existing directories without index.php. If I use try_files, it
will either lead to a 403 error (if no index is specified), or would
internally redirect the request to the index file (if it is specified),
leading to 404 error. The if condition correctly handles all the
non-existing files.
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

Rewrite before regex location

Joyce Babu May 04, 2016 05:28PM

Re: Rewrite before regex location

Francis Daly May 04, 2016 06:02PM

Re: Rewrite before regex location

Joyce Babu May 04, 2016 06:54PM

Re: Rewrite before regex location

Francis Daly May 04, 2016 07:16PM

Re: Rewrite before regex location

Joyce Babu May 04, 2016 07:46PM

Re: Rewrite before regex location

Anoop Alias May 04, 2016 10:24PM

Re: Rewrite before regex location

Joyce Babu May 06, 2016 04:18PM

Re: Rewrite before regex location

Francis Daly May 05, 2016 12:46PM

Re: Rewrite before regex location

B.R. May 06, 2016 07:54AM

Re: Rewrite before regex location

Joyce Babu May 06, 2016 04:38PM

Re: Rewrite before regex location

Joyce Babu May 06, 2016 06:26PM

Re: Rewrite before regex location

Joyce Babu May 06, 2016 06:30PM

Re: Rewrite before regex location

Robert Paprocki May 06, 2016 06:30PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

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