【问题标题】:Laravel Cleaner Url issue in ubuntu, How to fix it?ubuntu 中的 Laravel Cleaner Url 问题,如何解决?
【发布时间】:2014-08-09 21:57:03
【问题描述】:

我正在使用 laravel 最新版本。我刚刚添加了一条新路线,但它不起作用。

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

当我输入 localhost/index.php/about 它开始工作。 所以我检查了一些他们建议编辑 .htaccess 的文章,我也这样做了。

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

但它再次不起作用,因此我的配置文件中进行了一些更改。这是我的配置文件的内容。

    <VirtualHost *:80>
        ServerName sar.dev
        DocumentRoot "/var/www/laravel/public"
        <Directory "/var/www/laravel/public">
            Options Indexes FollowSymLinks MultiViews
            AllowOverride All
        </Directory> 
    </VirtualHost>

这个方法也失败了。我正在开发 ubuntu 13.10。有没有其他办法解决?

【问题讨论】:

  • 你启用rewrite_module了吗?
  • 确保你激活了 rewrite_module,或者只是切换到 NGINX :)
  • 检查是否启用了 rewrite_module 的一个非常简单的方法是从其中的代码中删除一些字符。例如。将RewriteCond 更改为MyWrongCond。你应该得到 500 Internal Server Error。
  • 您也可以尝试将/ 添加到index.php/$1 行,使其如下所示:^(.*)$ /index.php/$1。我注意到这在过去对我有用,但有一些类似的问题。

标签: php .htaccess ubuntu laravel laravel-4


【解决方案1】:

同意我的评论。我注意到您使用的是经过修改的 .htaccess,这不是 laravel 的默认设置。

尝试使用 laravel 默认的 .htaccess 文件,使用 / 旁边的 index.php 部分。

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

当遇到类似的错误时,该解决方案对我有所帮助,即在转到 /route 时该站点无法工作并且必须像您一样使用 /index.php/route。

【讨论】:

    猜你喜欢
    • 2016-10-04
    • 2015-09-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-25
    • 2021-12-08
    • 1970-01-01
    相关资源
    最近更新 更多