具有 IPv6 IP 地址的 RewriteRule 不起作用
RewriteRule with an IPv6 IP address does not work
我在 IPv6 地址内代理请求时遇到问题。
在 .htaccess/apache2.conf 上,我有:
RewriteRule (.*) http://18.4.15.8:80/path/ [P,L]
它工作正常,因为它是一个 IPv4 地址。
但是,它不起作用:
RewriteRule (.*) http://[27:ec:20:22:15::d3]:80/path/ [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/ [NE,P,L]
https://httpd.apache.org/docs/2.4/rewrite/flags.html#flag_ne
我在 IPv6 地址内代理请求时遇到问题。
在 .htaccess/apache2.conf 上,我有:
RewriteRule (.*) http://18.4.15.8:80/path/ [P,L]
它工作正常,因为它是一个 IPv4 地址。 但是,它不起作用:
RewriteRule (.*) http://[27:ec:20:22:15::d3]:80/path/ [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/ [NE,P,L]
https://httpd.apache.org/docs/2.4/rewrite/flags.html#flag_ne