【问题标题】:Laravel 5.2 reading from header authtoken on apacheLaravel 5.2 从 apache 上的标头 authtoken 读取
【发布时间】:2016-05-08 19:03:51
【问题描述】:

我正在尝试使用 JWT 身份验证,但无法读取 authtoken。 如果我沿着 url 发送令牌,它可以正常工作,但在标题中它不会。 这个链接说如果在 Apache 上,我们需要配置 apache 配置。我也这样做了,但它不起作用。 https://github.com/tymondesigns/jwt-auth/wiki/Authentication

RewriteEngine On
RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule .* - [e=HTTP_AUTHORIZATION:%1]

我尝试在 public/ 内部的 Laravel 5.2 中更改 .htacess

我当前的 .htaccess 看起来像这样

  <IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
      Options -MultiViews
    </IfModule>
   RewriteEngine On
   # Redirect Trailing Slashes If Not A Folder...
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteRule ^(.*)/$ /$1 [L,R=301]
   # Handle Front Controller...
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteRule ^ index.php [L]
   RewriteEngine On
   RewriteCond %{HTTP:Authorization} ^(.*)
   RewriteRule .* - [e=HTTP_AUTHORIZATION:%1]

</IfModule>

我错过了什么或做错了吗?

【问题讨论】:

    标签: php apache .htaccess laravel-5.2


    【解决方案1】:

    请行

    RewriteCond %{HTTP:Authorization} ^(.*)

    RewriteRule .* - [e=HTTP_AUTHORIZATION:%1]

    之前

    RewriteRule ^ index.php [L]

    完成.htaccess

    <IfModule mod_rewrite.c>
        <IfModule mod_negotiation.c>
            Options -MultiViews
        </IfModule>
    
        RewriteEngine On
    
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule ^(.*)/$ /$1 [L,R=301]
    
        RewriteCond %{HTTP:Authorization} .
        RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
    
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteRule ^ index.php [L]
    </IfModule>
    

    【讨论】:

    • 试过没用!。你能提供整个 .htacess 吗?
    • 我修改了答案
    • 尝试重新启动 apache,清除 laravel 的缓存,发布你的读取 header 的 php 代码
    猜你喜欢
    • 2021-04-25
    • 2013-11-15
    • 2017-01-15
    • 2014-07-27
    • 2018-05-13
    • 2016-03-29
    • 2019-10-08
    • 2017-05-13
    • 2016-08-04
    相关资源
    最近更新 更多