'Authorization' header 随请求一起发送,但在 apache_request_headers() 中丢失
'Authorization' header sent with request, but missing from apache_request_headers()
我正在向我的 PHP/Apache 服务器发送 Ajax 请求。该请求包含一个 Authorization
header,如下面我浏览器开发工具的屏幕截图所示:
在针对我的本地 Apache 服务器进行测试时,我可以使用 apache_request_headers()
从 PHP 访问 Authorization
header。但是,在我的生产服务器上(在共享 Linux 主机上)从 apache_request_headers
返回的数组中缺少 header,它看起来像这样:
array(10) {
["Cookie"] => string(31) "_ga=GA1.2.1071821587.1446317606"
["Accept-Language"] => string(14) "en-US,en;q=0.8"
["Accept-Encoding"] => string(19) "gzip, deflate, sdch"
["Referer"] => string(27) "http://goaunited.com/admin/"
["User-Agent"] => string(110) "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36"
["Accept"] => string(33) "application/json, text/plain, */*"
["Cache-Control"] => string(8) "no-cache"
["Pragma"] => string(8) "no-cache"
["Connection"] => string(5) "close"
["Host"] => string(13) "goaunited.com"
}
为什么 Authorization
header 不包含在我的生产服务器上的 apache_request_headers()
响应中?是什么导致它被省略?
经过一些快速搜索后发现设置重写规则有效
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
谁能告诉我它的作用?
是的..
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
或
SetEnvIf Authorization .+ HTTP_AUTHORIZATION=[=11=]
..in .htaccess 对我有用..
我按如下方式编辑了我的 .htaccess 文件。然后
添加最后一行解决了问题。
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ %{ENV:BASE}index.php [QSA,L]
SetEnvIf Authorization .+ HTTP_AUTHORIZATION=[=10=]
我正在向我的 PHP/Apache 服务器发送 Ajax 请求。该请求包含一个 Authorization
header,如下面我浏览器开发工具的屏幕截图所示:
在针对我的本地 Apache 服务器进行测试时,我可以使用 apache_request_headers()
从 PHP 访问 Authorization
header。但是,在我的生产服务器上(在共享 Linux 主机上)从 apache_request_headers
返回的数组中缺少 header,它看起来像这样:
array(10) {
["Cookie"] => string(31) "_ga=GA1.2.1071821587.1446317606"
["Accept-Language"] => string(14) "en-US,en;q=0.8"
["Accept-Encoding"] => string(19) "gzip, deflate, sdch"
["Referer"] => string(27) "http://goaunited.com/admin/"
["User-Agent"] => string(110) "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36"
["Accept"] => string(33) "application/json, text/plain, */*"
["Cache-Control"] => string(8) "no-cache"
["Pragma"] => string(8) "no-cache"
["Connection"] => string(5) "close"
["Host"] => string(13) "goaunited.com"
}
为什么 Authorization
header 不包含在我的生产服务器上的 apache_request_headers()
响应中?是什么导致它被省略?
经过一些快速搜索后发现设置重写规则有效
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
谁能告诉我它的作用?
是的..
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
或
SetEnvIf Authorization .+ HTTP_AUTHORIZATION=[=11=]
..in .htaccess 对我有用..
我按如下方式编辑了我的 .htaccess 文件。然后 添加最后一行解决了问题。
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ %{ENV:BASE}index.php [QSA,L]
SetEnvIf Authorization .+ HTTP_AUTHORIZATION=[=10=]