thinkphp6下无法获取header头中的Authorization(apache版)【转载】
转载链接:https://www.cnblogs.com/studyandstudy/p/11754381.html
今天开发php后台,发现无法获取到请求头里面的Authorization里面的token,最后搜索到原来得在.htaccess里面修改一下。
今天遇到在thinkphp框架中获取不到header头里边的 Authorization ,后来在.htaccess里面加多一项解决,记录下:
<IfModule mod_rewrite.c> Options +FollowSymlinks -Multiviews RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ index.php/?s=$1 [QSA,PT,L] #增加如下内容 SetEnvIf Authorization .+ HTTP_AUTHORIZATION=$0 </IfModule>
或者下边这样
<IfModule mod_rewrite.c> Options +FollowSymlinks -Multiviews RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ index.php/?s=$1 [QSA,PT,L] # Handle Authorization Header RewriteCond %{HTTP:Authorization} . RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] </IfModule> 最后一项解决thinkphp 框架开启路径重写,无法获取Authorization Header