我要求从网址中删除#字符。我正在使用以下配置对其进行测试。
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;
}
}
在所有这些重定向中 http://testing.example.com/#/something - 它提供index.html(预期提交hash.html的重写不正确) 但是http://testing.example.com/ $ /某些东西重写为dollar.html(正确) http://testing.example.com/&/something重写为ampersand.html(正确) http://testing.example.com/=/something重写为equal.html(正确) 当我加入http://testing.example.com/#/something重写日志时,似乎请求只是“/”而不是“/#/ something”
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"
.....
我在想这可能是因为浏览器对url unsafe character#进行了网址编码。 如果我对#字符进行编码并访问http://testing.example.com/%23/something - 这会正确地重写为hash.html
请咨询