代码之家  ›  专栏  ›  技术社区  ›  vdTOG

使用IPv6 IP地址重写规则不起作用

  •  2
  • vdTOG  · 技术社区  · 7 年前

    我在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]

    为什么?

    代理错误

    您的浏览器发送了此服务器无法理解的请求。

    原因:无法分析URI: http://%5b27:ec:20:22:15::d3%5d:80/path/index.html

    1 回复  |  直到 7 年前
        1
  •  3
  •   Webdesigner    7 年前

    这是因为 [ & ] . 它们通常不允许出现在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