【问题标题】:url not found error in laravel在 laravel 中找不到 url 错误
【发布时间】:2015-12-28 09:23:47
【问题描述】:

我在 ubuntu 上使用 Laravel 5 和新版本的 apache,当我尝试访问页面时:localhost 它可以工作,如果我尝试 localhost/index.php/my_page 它可以工作,但是如果我尝试 localhost/my_page,它没有。因此,通过搜索其他问题,我猜我的问题在于 .htaccess 文件。

根据我在网上看到的建议,我在 laravel/public 的 .htaccess 中添加了 rewriteBase 和 Options +FollowSymLinks:

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

      Options +FollowSymLinks
      RewriteEngine On
      RewriteBase /repos/kenrose/public

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

      # Handle Front Controller...
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteRule ^ index.php [L]
   </IfModule>

这就是我的 apache2.conf 文件的样子

    <Directory /repos/kenrose>
       Options Indexes FollowSymLinks
       AllowOverride All
       Require all granted
    </Directory>

我已经采纳了我发现的有关此问题的所有建议。有什么问题?

【问题讨论】:

    标签: apache .htaccess laravel mod-rewrite laravel-5.1


    【解决方案1】:

    试试这个:

    <IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>
    
    RewriteEngine On
    
    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/$ /$1 [L,R=301]
    
    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
    

    尝试删除您的+FollowSymLinks 部分,希望它会起作用。

    【讨论】:

    • 我试过了,没用。最初就是这样,我遇到了问题,我添加了 +FollowSymLinks 并没有帮助
    • 尝试删除重写规则^ index.php [L],然后运行。我不确定但希望如此。
    【解决方案2】:

    运行后

     a2enmod rewrite
    

    在命令终端中,一切正常。 我不知道这是做什么的,或者问题是什么。

    【讨论】:

      猜你喜欢
      • 2015-08-14
      • 1970-01-01
      • 2018-08-03
      • 2011-10-14
      • 2016-03-22
      • 2019-01-16
      • 2018-10-09
      • 1970-01-01
      • 2016-07-05
      相关资源
      最近更新 更多