Welcome! Log In Create A New Profile

Advanced

Re: args and rewrite vars always empty

Maxim Dounin
May 24, 2019 05:52AM
Hello!

On Fri, May 24, 2019 at 08:27:23AM +0000, User via nginx wrote:

> Hello,
>
> I'm trying to make simple rewrite to work and found that $args and other
> $1 vars from rewrite&try_files are always empty.
>
> nginx version: nginx/1.10.3
>
> Server config:
>
>   location /product/ {
>     rewrite ^/product/(.*)/$ /$1.txt last;
>    #    try_files $uri/ /test.php?test=$uri; # tries, then server conf
> was simplifies and all php environment was switched off for testing
>   }
>
> Request: domain.com/product/android/
>
> Expected result: "android.txt" file
>
> Real result: read ".txt" file.
>
> Error log with notice:
>
> 2019/05/24 07:51:55 [notice] 24217#24217: *560218 rewritten data:
> "/.txt", args: "", client: 1.1.1.1, server: domain.com, request: "GET
> /product/android/ HTTP/1.1", host: "domain.com"
> 2019/05/24 07:51:55 [error] 24217#24217: *560218 open()
> "/home/user/domain.com/.txt" failed (2: No such file or directory),
> client: 1.1.1.1, server: domain.com, request: "GET /product/android/
> HTTP/1.1", host: "domain.com"

The "rewrite" directive operates on the current - possibly
modified - URI, and most likely reason is that something went
wrong elsewhere in your config, so rewrite in question tests wrong
URI.

With "rewrite_log on;" you should get something like this in the
log:

2019/05/24 12:43:20 [notice] 31939#100103: *1 "^/product/(.*)/$" matches "/product/android/", client: 127.0.0.1, server: , request: "GET /product/android/ HTTP/1.0"
2019/05/24 12:43:20 [notice] 31939#100103: *1 rewritten data: "/android.txt", args: "", client: 127.0.0.1, server: , request: "GET /product/android/ HTTP/1.0"

The first line shows actual matching - regular expression itself
and the string it matches, and the second one shows the result.
The above two lines were obtained with the following trivial
configuration:

server {
listen 8080;

rewrite_log on;

location /product/ {
rewrite ^/product/(.*)/$ /$1.txt last;
}
}

And it seems to work fine without any problems. If it doesn't
work for you, please show exact configuration and both log lines
produced.

--
Maxim Dounin
http://mdounin.ru/
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

args and rewrite vars always empty

User via nginx May 24, 2019 04:28AM

Re: args and rewrite vars always empty

Patrick May 24, 2019 04:42AM

Re: args and rewrite vars always empty

User via nginx May 24, 2019 04:56AM

Re: args and rewrite vars always empty

Maxim Dounin May 24, 2019 05:52AM

Re: args and rewrite vars always empty

User via nginx May 24, 2019 06:44AM

Re: args and rewrite vars always empty

Maxim Dounin May 24, 2019 07:40AM

Re: args and rewrite vars always empty

User via nginx May 24, 2019 07:52AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

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