I'm trying to use Nginx (1.21.3
) rewrite, but somehow it deletes the /
key when it's first in string.
rewrite rule:
#nginx not relevant conf here
location / {
rewrite ^(.*)data/([0-9]+)/(.+)?$ $1processor.php?key=$2&data=$3 last;
}
#nginx not relevant conf here
When I use this rewrite rule for any url I tested, it was okay. When I tried url like the example below, it somehow omitted the /
in the beginning.
https://example.com/data/9/%2F*-%2B.%60!%40%23%24%25%5E%26*()_%2B%60-%3D%5B%5D%3B%27%5C%2C.%2F%7B%7D%3A%22%7C%3C%3E%3F
When I reloaded nginx
with notices and rewrite_log=on;
I got the output:
2021/09/25 13:08:29 [notice] 528#528: *11710 "^(.*)data/([0-9]+)/(.+)?$" matches "/data/199/*-+.`!@#$%^&*()_+`-=[];'\,./{}:"|<>?", client: 192.168.255.107, server: localhost, request: "GET /data/199/%2F%2A-%2B.%60%21%40%23%24%25%5E%26%2A%28%29_%2B%60-%3D%5B%5D%3B%27%5C%2C.%2F%7B%7D%3A%22%7C%3C%3E%3F HTTP/2.0", host: "example.com", referrer: "https://example.com/"
PHP (8.0.10
) $_GET["data"]
output is (as you can see without /
thus not exact math):
*-+.`!@#$%^&*()_+`-=[];'\,./{}:"|<>?
How can I solve it?