nginx rewrite#字符不工作urlencode

nginx rewrite#字符不工作urlencode,nginx,url-rewriting,url-encoding,urldecode,nginx-location,Nginx,Url Rewriting,Url Encoding,Urldecode,Nginx Location,我需要从url中删除#字符。我用以下配置测试它 server { listen 80 ; listen [::]:80; root /var/www/testing.example.com/html; index index.html index.htm; server_name testing.example.com; error_log /var/log/nginx/testing.exa

我需要从url中删除#字符。我用以下配置测试它

server {
        listen 80 ;
        listen [::]:80;
        root /var/www/testing.example.com/html;
        index index.html index.htm;
        server_name  testing.example.com;
        error_log    /var/log/nginx/testing.example.com.log debug;
        rewrite_log on;
        location / {
                try_files $uri $uri/  =404;
                expires -1;
                add_header Pragma "no-cache";
                add_header Cache-Control "no-store, no-cache, must-revalidate, post-check=0, pre-check=0";
                rewrite ^/\$/(.*)$   $scheme://testing.example.com/dollar.html redirect;
                rewrite ^/\#/(.*)$   $scheme://testing.example.com/hash.html redirect;
                rewrite ^/\&/(.*)$   $scheme://testing.example.com/ampersand.html redirect;
                rewrite ^/\=/(.*)$   $scheme://testing.example.com/equal.html redirect;
                rewrite ^/\</(.*)$   $scheme://testing.example.com/lessthan.html redirect;
                rewrite ^/\%/(.*)$   $scheme://testing.example.com/percentage.html redirect;
                rewrite ^/\^/(.*)$   $scheme://testing.example.com/caret.html redirect;
        }
}
我想这可能是因为浏览器对url不安全字符的url编码。 如果我对#字符进行编码并访问-这将正确地重写为hash.html


请注意

URI的
#
部分(也指)不是发送到服务器的URI的一部分。谢谢Richard,是的,服务器中没有URL片段部分。因此,使用服务器端重定向似乎无法满足此要求。
    2017/01/12 09:44:57 [debug] 19270#0: *2 http script regex: "^/\$/(.*)$"
    2017/01/12 09:44:57 [notice] 19270#0: *2 "^/\$/(.*)$" does not match "/", client: 192.168.3.26, server: testing.example.com, request: "GET / HTTP/1.1", host: "testing.example.com"
    2017/01/12 09:44:57 [debug] 19270#0: *2 http script regex: "^/#/(.*)$"
    2017/01/12 09:44:57 [notice] 19270#0: *2 "^/#/(.*)$" does not match "/", client: 192.168.3.26, server: testing.example.com, request: "GET / HTTP/1.1", host: "testing.example.com"
    .....