【问题标题】:laravel4 routes works with route /, but does not for other routeslaravel4 路由适用于路由 /,但不适用于其他路由
【发布时间】:2014-07-25 18:41:53
【问题描述】:

我搭建了一个laravel4项目,但是路由只对路由/有效。

我也为项目设置了一个vhost,vhost指向laravel4/public

我在 routes.php 中有以下代码

Route::get('/', function()
  {
      return View::make('home');
  });

  Route::get('help', function() {
      return "asdfsafas";
  });

当我转到 / 时,它显示正确。但是如果我去 /help,它会显示 The requested URL /help was not found on this server.

【问题讨论】:

  • 哦,我忘了添加 index.php :( 在我输入 xxxx.dev/index.php/help 后,它可以工作。但是如果只输入 xxxx.dev/help,我怎样才能让它工作?
  • 你所拥有的应该可以正常工作 - 你使用什么作为 http 服务器,apache?在你的 laravel 根目录中使用 'php artisan serve' 试试。

标签: php laravel-4


【解决方案1】:

您似乎没有启用 apache-rewrite 模块。很可能它将安装在您的系统上但未启用。您可以像这样从终端启用它。

sudo a2enmod rewrite

然后,使用以下命令重新启动 apache:

sudo service apache2 restart

这应该可以解决问题。

【讨论】:

    【解决方案2】:

    将您的DocumentRoot 设置为

    laravel4/public/index.php
    

    并重新启动 Apache。然后你可以访问像

    这样的路线
    /help
    

    而不是 index.php/help

    【讨论】:

      猜你喜欢
      • 2020-12-04
      • 2018-12-31
      • 2019-04-08
      • 2016-07-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-06
      相关资源
      最近更新 更多