问题
This is my .htaccess
file:
RewriteEngine on
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
Even though I have added below line to my .htaccess
file I cannot access $_SERVER['HTTP_AUTHORIZATION']
.
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
When I'm doing print_r($_SERVER)
I can't find HTTP_AUTHORIZATION
.
I have googled for an answer but none of them worked.
回答1:
If you're using rewrite rules to pass this header - it may be prefixed by REDIRECT_
Try $_SERVER['REDIRECT_HTTP_AUTHORIZATION']
.
But since 2.0.13 Yii has an abstraction for this, I suggest to use it:
- Request::getAuthUser() to get user.
- Request::getAuthPassword() to get password.
- Request::getAuthCredentials() to get both.
回答2:
I have previously faced same issue and I solved by adding this line at the top of my .htaccess
that is at the root directory
SetEnvIf Authorization .+ HTTP_AUTHORIZATION=$0
来源:https://stackoverflow.com/questions/51806446/serverhttp-authorization-is-missing