Rewrite before regex location
Francis Daly
francis at daoine.org
Thu May 5 16:44:24 UTC 2016
On Thu, May 05, 2016 at 05:13:29AM +0530, Joyce Babu wrote:
Hi there,
> Is it possible to do something like this?
>
> location /test/ {
> rewrite "^/test/([a-z]+).php$" /php-fpm/test/test.php?q=$1 last;
> }
>
> location ~ ^/php-fpm/ {
> location ~ [^/]\.php(/|$) {
> fastcgi_split_path_info ^/php-fpm(.+?\.php)(/.*)$;
>
> fastcgi_pass 127.0.0.1:9000;
> fastcgi_index index.php;
> include fastcgi_params;
> }
> }
>
>
> What I have tried to do here is rewrite to add a special prefix (/php-fpm)
> to the rewritten urls. and nest the php location block within it. Then use
> fastcgi_split_path_info to create new $fastcgi_script_name without the
> special prefix. I tried the above code, but it is not working.
> fastcgi_split_path_info is not generating $fastcgi_script_name without the
> /php-fpm prefix.
That's because your fastcgi_split_path_info pattern does not match -
.php is not followed by / in your rewritten url.
Because of the location{} you are in, it is probably simplest to just
replace the second capture part of that pattern with (.*)$.
Cheers,
f
--
Francis Daly francis at daoine.org
More information about the nginx
mailing list