首页 > 解决方案 > 如果 url 中没有 index.php,Laravel 7.10 新安装不起作用

问题描述

我已经安装了全新的 laravel 安装,一切正常,除了如果我在最后没有输入 index.php 的情况下转到 url,那么它就不起作用。

我在用:

http://localhost/index.php

在这种情况下,页面显示正确,但如果我只输入:

http://localhost/

然后它没有按预期工作。

如何查看它是否有效,我已经安装了调试栏,在第一种情况下它显示但在第二种情况下它不是。

我已经更新了 apache2 配置,以便它在公共目录中启动,并且我确保它接受 000-default.conf 中带有 DirectoryIndex index.php 的 php。

我是否应该设置一些东西,以便在浏览器中点击目录时强制重定向到 index.php?

这是我从 phpinfo 中获得的 apache2 处理程序中已加载模块的信息,我可以看到 mod_rewrite

Loaded Modules

core mod_so mod_watchdog http_core mod_log_config mod_logio mod_version mod_unixd mod_access_compat mod_alias mod_auth_basic mod_authn_core mod_authn_file mod_authz_core mod_authz_host mod_authz_user mod_autoindex mod_deflate mod_dir mod_env mod_filter mod_mime prefork mod_negotiation mod_php7 mod_reqtimeout mod_rewrite mod_setenvif mod_status 

标签: laravelapache

解决方案


请更改 httpd.conf 文件的内容,如下所示。

<IfModule dir_module>
    DirectoryIndex index.php index.pl index.cgi index.asp index.shtml index.html index.htm \
                   default.php default.pl default.cgi default.asp default.shtml default.html default.htm \
                   home.php home.pl home.cgi home.asp home.shtml home.html home.htm
</IfModule>


...

Listen 8094
<VirtualHost *:8094>

DocumentRoot "D:\yoursouce\public"

    <Directory "D:\yoursouce\public">

        Require all granted
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>
...

然后尝试

http://localhost:8094/

此致


推荐阅读