Apache2 RequestHeader 读取值为 ISO-8859-1 而不是 UTF-8

Apache2 RequestHeader 读取值为 ISO-8859-1 而不是 UTF-8

这是一个特殊情况,我使用 Apachemod_proxy在我的tomcat和Apache前面也添加了RequestHeadermod_headers, 谢谢mod_rewrite。如果 URI 中有特殊字符,则它们被“读取”为ISO-8859-1。即使我在规则中写入了硬性特殊值,如“hélo”。如果我的 conf 文件保存为ISO-8859-1,但是如果 conf 文件保存为UTF-8,这是 KO (é变得é在运行时)。我没有找到这个编码在哪里配置。我在 Windows 和 Linux Apache 服务器上都试过了。这里是配置文件:

<VirtualHost *:80>
ServerName apache.convertigo.net
ProxyPass / http://httpbin.org/anything/
ProxyPassReverse / http://httpbin.org/anything/

RewriteEngine On
  RewriteRule ^(.*)$ - [E=X_REQUEST_URI:%{REQUEST_URI},E=X_REQUEST_HOST:%{HTTP_HOST},E=X_HTTPS_STATE:%{HTTPS}]
  RequestHeader set x-request-uri  "%{X_REQUEST_URI}e"  env=X_REQUEST_URI
  RequestHeader set x-request-host "%{X_REQUEST_HOST}e" env=X_REQUEST_HOST
  RequestHeader set x-https-state  "%{X_HTTPS_STATE}e"  env=X_HTTPS_STATE
  RequestHeader set x-frontal      "apache"
  RequestHeader set x-helo         "hélo"
</VirtualHost>

这里是一个回显 URI 的测试 URL(参见X-请求-Uri):http://apache.convertigo.net/hélo

结果如下:

{
  "args": {}, 
  "data": "", 
  "files": {}, 
  "form": {}, 
  "headers": {
    "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8", 
    "Accept-Encoding": "gzip, deflate", 
    "Accept-Language": "fr-FR,en-US;q=0.8,fr;q=0.6,en;q=0.4", 
    "Cache-Control": "max-age=0", 
    "Connection": "close", 
    "Dnt": "1", 
    "Host": "httpbin.org", 
    "Upgrade-Insecure-Requests": "1", 
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36", 
    "X-Forwarded-Host": "apache.convertigo.net", 
    "X-Forwarded-Server": "apache.convertigo.net", 
    "X-Frontal": "apache", 
    "X-Helo": "h\u00c3\u00a9lo", 
    "X-Https-State": "off", 
    "X-Request-Host": "apache.convertigo.net", 
    "X-Request-Uri": "/h\u00c3\u00a9lo"
  }, 
  "json": null, 
  "method": "GET", 
  "origin": "217.167.129.14, 54.171.110.0", 
  "url": "http://apache.convertigo.net/anything/h\u00e9lo"
}

我期望X-请求-Uri“/h\u00e9lo”(喜欢网址) 并不是“/h\u00c3\u00a9lo”

相关内容