Laravel 5需要使用Apache虚拟主机的index.php

Sve*_*art 24 php apache .htaccess laravel laravel-5

当我加载非root用户的页面时,如果没有index.php,页面将不会在路由之前加载.我得到的错误:

 Not Found

 The requested URL /login was not found on this server.

 Apache/2.4.7 (Ubuntu) Server at mydomain.com Port 80
Run Code Online (Sandbox Code Playgroud)

首先,我有一个包含以下内容的虚拟主机文件:

//also tried adding DirectoryIndex here before <directory>
<directory /var/www/mydomain.com>
    DirectoryIndex index.php
    AllowOverride ALL
</directory>
Run Code Online (Sandbox Code Playgroud)

和我公开的.htacces:

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

    RewriteEngine On

    # Redirect Trailing Slashes...
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>
Run Code Online (Sandbox Code Playgroud)

我有另一个域在同一台服务器上具有相同的.htaccess和appache配置,它工作正常.我也重启了apache.如果我在index.php/route页面上使用phpinfo,我会在Loaded Modules中看到:

mod_rewrite mod_setenvif 
Run Code Online (Sandbox Code Playgroud)

使用xampp运行网站localy时一切正常.几个小时我现在正在尝试,但我无法解决它或发现任何错误(日志是空的)或任何我还没有尝试过的解决方案.

编辑:

我在数字海洋VPS上使用Ubuntu Ubuntu 14.04 x64.我试着再打开和关闭(如建议的那样).PHP版本5.5.9-1ubuntu4.9.我按照教程配置了所有内容(除了direcoty部分).我更改了apache日志的位置,并在给定目录上创建了一个文件error.log,但没有错误.

我目前的appache配置是:这个 (我已经三次检查了域名所在的白色部分).

当我运行apache2ctl -t D DUMP_VHOSTS时,我得到了

在此输入图像描述

这看起来很好,也尝试禁用默认配置,但它没有帮助.

注意:我已经用mydomain.com取代了我的真实域名,实际上我在这些地方使用我的真实域名.

以为我如何确定conf文件即时编辑是域名使用的?

Neo*_*Neo 12

对于Laravel 5,这是正确的替代htaccess规则,建议在默认设置不起作用时使用:

Options +FollowSymLinks
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
Run Code Online (Sandbox Code Playgroud)

Options +FollowSymLinks相信起着因为重要的作用DirectotyIndex就像一个符号链接的行为.

还要检查/app/config/app.php以确保没有将Config('app.url')设置为包含index.php.

如果您在子目录中安装了laravel,请参阅: 如何在url生成的laravel中删除"public/index.php"?


Cen*_*bit 8

您是否尝试将其全部关闭(关机),然后再将其打开?

如果一切都如你所说,它应该工作.我会尝试重新启动,看看它是否有任何改变.

如果没有,请使用您正在使用的操作系统进行更新.


Sve*_*art 6

我最终删除了完整的conf文件,并从那个正在工作的文件中再次复制.我从laravel中取出默认的.htaccess并且它起作用了.不幸的是,我仍然不知道出了什么问题.当前的conf文件看起来像

<Directory /var/www/mydomain.com>
    AllowOverride ALL
    DirectoryIndex index.php
</Directory>
Run Code Online (Sandbox Code Playgroud)

我的.htaccess in/public

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

    RewriteEngine On

    # Redirect Trailing Slashes...
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>
Run Code Online (Sandbox Code Playgroud)