【问题标题】:Laravel redirects to a route but then apache gives 404 errorLaravel 重定向到一个路由,但是 apache 给出 404 错误
【发布时间】:2014-05-10 13:35:28
【问题描述】:

我有一个网站在不同的 url (staging) 中的同一台服务器上运行,但现在我已经部署了该网站,并且基本 url ("/") 被重定向到登录 url (所以 laravel 是排序的工作),但后来我从 apache 收到 404 错误。

如果我使用 sub.domain.com/index.php/route,它可以工作,但如果我使用 sub.domain.com/route 会重定向到登录路由并给出 404 错误。

我还更改了 routes.php 以在路由“/”中返回登录视图,并正确显示登录表单。

【问题讨论】:

    标签: php apache .htaccess redirect laravel


    【解决方案1】:

    添加后

    AllowOverride All
    

    到虚拟主机配置,让它工作。可能默认配置不允许重定向?

    这是我的最终(和工作)虚拟主机配置:

    DocumentRoot /var/www/sitefolder/public
     ServerName site.domain.com
     <Directory /var/www/sitefolder/public>
      AllowOverride All
      allow from all
      Options +Indexes
    </Directory>
    

    【讨论】:

    • 是的。这里发生的事情是 /public/ 中有一个 .htaccess 可以修复 url 以隐藏 index.php。但是,要运行它,它需要 AllowOverride All,因为 .htaccess 是关于发出未在 /etc/apache(或您的发行版放置的任何地方)配置集群中指定的进一步 apache 服务器配置
    【解决方案2】:

    问题可能来自您的 Apache 服务器中的一个名为 rewrite 模块的模块。 在 Windows 中,您可以从 httpd.conf 中取消注释这一行

    #LoadModule rewrite_module modules/mod_rewrite.so

    我正在运行 Ubuntu 14.04 并使用

    启用它

    sudo a2enmod rewrite

    重启 Apache 试试这些。 它也可能对你有用。

    【讨论】:

    • Tnx 很多朋友。你是最棒的:*
    • 刚刚救了我,虽然我遇到了一些错误,但我的问题都解决了,谢谢
    【解决方案3】:

    VirtualHost

    仅将这些行添加到您的 apache 的 httpd.conf 中:

    <Directory /var/www/sitefolder/public>
      AllowOverride All
      allow from all
      Options +Indexes
    </Directory>
    

    或者您可以将第一行替换为:

    <Directory />
    

    如果一切都不起作用,您可以尝试:

    <Directory />
        Options FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-12-23
      • 1970-01-01
      • 2015-07-30
      • 2019-10-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-15
      相关资源
      最近更新 更多