为什么这个 Laravel 8 API 抛出内部服务器错误?

Why does this Laravel 8 API throw an Internal Server Error?

我正在使用我克隆的 Laravel 8 API。

它在实时服务器上工作,但在我的本地 WAMP 服务器上它抛出 500 Internal Server Error

apache_error.log显示:

Invalid command 'Header', perhaps misspelled or defined by a module not included in the server configuration

.htaccess文件的内容,放在public目录下(虚拟主机指向的地方)是:

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews -Indexes
    </IfModule>

    RewriteEngine On

    Header always set Access-Control-Allow-Origin "*"
    Header always set Access-Control-Max-Age "1000"
    Header always set Access-Control-Allow-Headers "Accept, Accept-Encoding, Authorization, Content-Type, Origin, X-Requested-With"
    Header always set Access-Control-Allow-Methods "GET, DELETE, PATCH, POST, PUT, OPTIONS"

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

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.+)/$
    RewriteRule ^ %1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

注意:

其他 PHP / Laravel 应用程序 在本地环境中工作

此外,mod_rewrite 已启用

是什么导致了这个问题?

"...或由未包含在服务器配置中的模块定义" 建议您需要先启用一个模块。 Header 是 Apache 中 mod_headers 的一部分。

在您的 WAMP 中启用该模块以使 Header 工作。

转到 wamp64\bin\apache\apache2.4.46\conf,打开 httpd.conf 找到 LoadModule headers_module modules/mod_headers.so 并取消注释。

然后重启WAMP。