我在代理 IPv6 地址内的请求时遇到问题。
在 .htaccess/apache2.conf 上,我有它:
RewriteRule (.*) http://18.4.15.8:80/path/$1 [P,L]
它工作正常,因为它是 IPv4 地址。 但是,它不起作用:
RewriteRule (.*) http://[27:ec:20:22:15::d3]:80/path/$1 [P,L]
为什么?
错误日志:
Proxy Error
Your browser sent a request that this server could not understand. The proxy server could not handle the request GET /index.html.
Reason: URI cannot be parsed: http://%5b27:ec:20:22:15::d3%5d:80/path/index.html
最佳答案
这是因为[
& ]
。 URL 中通常不允许使用这些字符,因此服务器将其转义为 %b5
和 %5d
。为了防止这种情况,请在重写规则中使用 NE 标志:
RewriteRule (.*) http://[27:ec:20:22:15::d3]:80/path/$1 [NE,P,L]
https://httpd.apache.org/docs/2.4/rewrite/flags.html#flag_ne
关于apache - 具有 IPv6 IP 地址的 RewriteRule 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46609891/