【问题标题】:laravel virtualhost 404 errorlaravel 虚拟主机 404 错误
【发布时间】:2014-11-29 22:59:48
【问题描述】:

我的 ubuntu 服务器上有 apache2。

有我的 /etc/apache2/sites-available/laravel.conf

<VirtualHost *:80>
    ServerName http://laravel.mysite.com/
    DocumentRoot "/var/www/laravel/public"
    <Directory "/var/www/laravel/public">
        AllowOverride all
        Order allow,deny
       Allow from all
    </Directory>
</VirtualHost>

我已经打开了 apache 的 mod_rewrite 函数。

有我的 /var/www/laravel/app/routes.php

<?php
Route::get('/', function()
{
    return View::make('home/index');
});
Route::get('/hehe', function()
{
    return "hehe';
});

有我的 /var/www/laravel/public/.htaccess

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

现在,我可以访问http://laravel.mysite.com,但是当我访问http://laravel.mysite.com/hehe 时,它会出现404 错误。是不是我配置错了?

【问题讨论】:

    标签: .htaccess laravel apache2


    【解决方案1】:

    虽然这个问题已经很老了,但对于任何仍然感兴趣的人(就像我一样,但设法解决了问题),我创建了一个检查表,以便在 Laravel 路由抛出 404 或 403 错误时进行检查。

    我假设 Laravel 最初安装的 public/.htaccess 文件没有被修改。

    1. 确保将 部分插入到具有正确路径的虚拟主机的 apache 配置文件中。

    2. 确保在 部分中有 AllowOverride All,而不是 None 以允许路由(避免 404 错误)。

    3. 确保在 部分中使用Require all granted,而不是denied,以授予访问者查看网站的权限(避免 403 错误)。

    4. 如果您在应用中使用符号链接,可能还需要在 部分中包含 Options FollowSymLinks

    5. 确保在 apache 中启用了 rewrite 模块:$ sudo a2enmod rewrite

    6. 并且不要忘记重新启动 apache 服务器以使更改生效。

    【讨论】:

      【解决方案2】:

      我唯一要做的就是设计 apache2.conf,添加这个:

      <Directory /var/www/laravel/public>
          Options FollowSymLinks
          AllowOverride All
      </Directory>
      

      【讨论】:

        猜你喜欢
        • 2017-05-27
        • 2017-03-21
        • 1970-01-01
        • 2016-07-08
        • 2020-04-09
        • 1970-01-01
        • 2019-01-01
        • 2014-02-15
        • 2017-09-07
        相关资源
        最近更新 更多