args and rewrite vars always empty

Maxim Dounin mdounin at mdounin.ru
Fri May 24 09:50:11 UTC 2019


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/


More information about the nginx mailing list