.htaccess - Lumen 从请求中获取 header key

标签 .htaccess api lumen request-headers lumen-5.4

我正在使用 Lumen 框架在 API 中实现身份验证。我在本地主机上的 header 中传递 api_token ,它工作正常。在Linux服务器上上传时,它在api_token header 中给出空值。我正在使用 postman 来检查回复

这是我的 AuthMiddleware@handle 代码,用于检查该值。

echo $request->header("api_token");

我大部分时间都在谷歌上搜索,发现需要进行 public/.htaccess 更改,但对我来说不起作用。

# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

在我的 .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]

# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>

我不知道如何配置 apache2 的请求 header 。

最佳答案

请求 header 键应避免使用下划线连字符 更常见,您应该将请求 header 键重命名为api-token。根据Apache 2.4 new features :

Translation of headers to environment variables is more strict than before to mitigate some possible cross-site-scripting attacks via header injection. Headers containing invalid characters (including underscores) are now silently dropped. Environment Variables in Apache has some pointers on how to work around broken legacy clients which require such headers. (This affects all modules which use these environment variables.)

关于.htaccess - Lumen 从请求中获取 header key ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47845778/

相关文章:

javascript - 无法在 XMLHttpRequest.xhr.onload (Unsplash API) 处读取未定义的属性

asp.net-mvc - 从 IP 地址远程访问本地 ASP.NET Core 应用程序?

php - 流明 : How to fix the SQLSTATE[42000]: Syntax error or access violation: 1071 on laravel lumen

javascript - Flash fscommand 无法运行 Internet Explorer 9

jquery - 流明ajax帖子

lumen - 调用未定义的方法 Laravel\Lumen\Routing\Router::where()

javascript - 缓存 uploadify 文件会使 chrome 崩溃

.htaccess - 使用 cPanel 和插件域时 htaccess 如何工作

apache - htaccess 将 mydomain.com/knowledgebase.php 更改为 mydomain.com

.htaccess: "redirect permanent",回退到 "RewriteRule"