404使用apache2 virtualhost在laravel 6.4中调用api时出错

404使用apache2 virtualhost在laravel 6.4中调用api时出错,laravel,api,apache2,http-status-code-404,virtualhost,Laravel,Api,Apache2,Http Status Code 404,Virtualhost,我在Ubuntu18.04上安装了Laravel6.4,带有PHP7.2和apache2。我已经构建了一个开发api的案例研究,当我执行php artisan serve命令并使用postman进行查询时,一切都很好。但是如果我创建一个virtualhost,我可以毫无问题地查看网站,然而,当通过邮递员执行查询时,我得到404错误。 .htaccess文件是默认情况下带来laravel的文件: <IfModule mod_rewrite.c> <IfModule mod_neg

我在Ubuntu18.04上安装了Laravel6.4,带有PHP7.2和apache2。我已经构建了一个开发api的案例研究,当我执行php artisan serve命令并使用postman进行查询时,一切都很好。但是如果我创建一个virtualhost,我可以毫无问题地查看网站,然而,当通过邮递员执行查询时,我得到404错误。 .htaccess文件是默认情况下带来laravel的文件:

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

RewriteEngine On

# 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>

选项-多视图-索引
重新启动发动机
#句柄授权头
RewriteCond%{HTTP:Authorization}。
重写规则。*-[E=HTTP\U授权:%{HTTP:AUTHORIZATION}]
#如果不是文件夹,则重定向尾部斜杠。。。
重写cond%{REQUEST_FILENAME}-D
重写cond%{REQUEST_URI}(+)/$
重写规则^1[L,R=301]
#处理前控制器。。。
重写cond%{REQUEST_FILENAME}-D
重写cond%{REQUEST_FILENAME}-F
重写规则^index.php[L]
我的虚拟主机如下所示:

<VirtualHost test-api.local:80>
    ServerName test-api.local

    DocumentRoot /var/www/html/restlav/public
    DirectoryIndex index.php

    ErrorLog ${APACHE_LOG_DIR}/test-api.local-error.log
    CustomLog ${APACHE_LOG_DIR}/test-api.local-access.log combined

    <Directory "/var/www/html/restlav">
            Options +FollowSymLinks
            RewriteEngine On
            AllowOverride None
            Require all granted
    </Directory>
</VirtualHost>

ServerName test-api.local
DocumentRoot/var/www/html/restlav/public
DirectoryIndex.php
ErrorLog${APACHE_LOG_DIR}/test-api.local-error.LOG
CustomLog${APACHE_LOG_DIR}/test-api.local-access.LOG组合
选项+FollowSymLinks
重新启动发动机
不允许超限
要求所有授权
我已经尝试过做出官方文件中建议的更改,但什么都没有。“重写”模块已启用。如果有人能帮助我,我将提前表示感谢。

在部分中,您需要将AllowOverride设置为All:

<VirtualHost test-api.local:80>
    ServerName test-api.local

    DocumentRoot /var/www/html/restlav/public
    DirectoryIndex index.php

    ErrorLog ${APACHE_LOG_DIR}/test-api.local-error.log
    CustomLog ${APACHE_LOG_DIR}/test-api.local-access.log combined

    <Directory "/var/www/html/restlav">
            Options +FollowSymLinks
            RewriteEngine On
            AllowOverride All
            Require all granted
    </Directory>
</VirtualHost>
不要忘记最后重新启动apache服务器以使更改生效:

$ sudo systemctl restart apache2
在该部分中,您需要将AllowOverride设置为All:

<VirtualHost test-api.local:80>
    ServerName test-api.local

    DocumentRoot /var/www/html/restlav/public
    DirectoryIndex index.php

    ErrorLog ${APACHE_LOG_DIR}/test-api.local-error.log
    CustomLog ${APACHE_LOG_DIR}/test-api.local-access.log combined

    <Directory "/var/www/html/restlav">
            Options +FollowSymLinks
            RewriteEngine On
            AllowOverride All
            Require all granted
    </Directory>
</VirtualHost>
不要忘记最后重新启动apache服务器以使更改生效:

$ sudo systemctl restart apache2

AllowOverride AllowOverride all