具有IPv6 IP地址的RewriteRule不起作用 [英] RewriteRule with an IPv6 IP address does not work
问题描述
我在代理IPv6地址中的请求时遇到问题.
I am having problems to proxy requestions inside a IPv6 address.
在.htaccess/apache2.conf上,我拥有它:
On .htaccess/apache2.conf, I have it:
RewriteRule (.*) http://18.4.15.8:80/path/$1 [P,L]
它工作正常,因为它是IPv4地址. 但是,它不起作用:
It works fine, because it is a IPv4 address. But, it does not works:
RewriteRule (.*) http://[27:ec:20:22:15::d3]:80/path/$1 [P,L]
为什么?
错误日志:
代理错误
您的浏览器发送了该服务器无法理解的请求. 代理服务器无法处理GET/index.html请求.
Your browser sent a request that this server could not understand. The proxy server could not handle the request GET /index.html.
原因:无法解析URI: http://%5b27:ec:20:22:15 :: d3%5d:80/path/index.html
Reason: URI cannot be parsed: http://%5b27:ec:20:22:15::d3%5d:80/path/index.html
推荐答案
是因为[
& ]
.通常不允许在URL中使用Thay,因此服务器会将其转义为%b5
和%5d
.为了防止这种情况,请在您的重写规则中使用NE标志:
It's because of [
& ]
. Thay are usually not allowed in a URL and so the server is escaping it to %b5
and %5d
. To prevent this use the NE Flag in your Rewrite Rule:
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
这篇关于具有IPv6 IP地址的RewriteRule不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!