1. 程式人生 > >關於thinkphp 框架開啟路徑重寫,無法獲取Authorization Header

關於thinkphp 框架開啟路徑重寫,無法獲取Authorization Header

今天遇到在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

原文地址:https://my.oschina.net/qqlet/blog/1859306