【问题标题】:Laravel routes & .htaccess file not working on 1and1 hostingLaravel 路由和 .htaccess 文件不适用于 1and1 托管
【发布时间】:2015-04-27 10:24:02
【问题描述】:

我的客户最近从 1and1.com 托管公司购买了 linux 1&1 无限包。我在 Laravel 4.2 框架中为他构建了应用程序。该应用程序在我的本地机器以及我自己的 VPS 上运行得非常好。但是当我在客户端主机上设置文件时,看起来 .htaccess 文件不起作用。这就是为什么,laravel 路由不起作用,我在尝试访问站点的不同路由时不断收到 404 错误消息。

我对这个问题进行了很多研究,发现很多人都遇到了同样的问题,但找不到解决这个问题的真正方法。

这是 .htaccess 代码:

<IfModule mod_rewrite.c>
  Options -MultiViews
  RewriteEngine On

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

我正在使用 Laravel 4.2

【问题讨论】:

  • 服务器上是否启用了 mod_rewrite?你的虚拟主机指向公用文件夹吗?
  • 我真的不能说,因为我提到我的客户从 1and1.com 购买了这个共享主机,我无权访问他们的 httpd.conf 文件
  • 看看这个answer

标签: php apache .htaccess laravel routes


【解决方案1】:

我在 1&1 托管解决方案中遇到了同样的问题。我建议添加:

RewriteBase /

这对我有用。

一切顺利, M

【讨论】:

【解决方案2】:

我使用 Laravel 5.2,谢谢,它也适用于我,谢谢 我将 RewriteBase 添加到我的 .htaccess 文件中

<IfModule mod_rewrite.c>
    RewriteBase /
    <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]
</IfModule>

【讨论】:

  • 我正在使用 laravel 5.6
【解决方案3】:

这对我有用,我的.htaccess中只有以下内容

RewriteBase /

Options +FollowSymLinks
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-12-13
    • 2017-08-23
    • 2018-11-10
    • 1970-01-01
    • 1970-01-01
    • 2020-11-12
    • 2019-10-05
    • 2017-08-06
    相关资源
    最近更新 更多