【问题标题】:Laravel showing 404 on all routes in Apache virtual hostLaravel 在 Apache 虚拟主机中的所有路由上显示 404
【发布时间】:2016-02-10 00:28:43
【问题描述】:

我有两个 laravel 应用程序,我希望将它们放在实时 Apache 服务器上。操作系统是 CentOs。我按照这个教程设置了一个虚拟主机:https://www.digitalocean.com/community/tutorials/how-to-set-up-apache-virtual-hosts-on-centos-7

当我尝试访问我的链接 http://lara.ci/public/ 时,我得到的只是 404 Not Found。以下是我的网站可用文件:

<VirtualHost *:80>

    ServerName www.lara.ci
    ServerAlias lara.ci
    DocumentRoot /var/www/lara.ci/public_html/public
    ErrorLog /var/www/lara.ci/error.log
    CustomLog /var/www/lara.ci/requests.log combined
</VirtualHost>

应用程序的文件位于 public_html 文件夹中。我什至在搜索完后尝试了以下方法,但无法正常工作:

在httpd.conf中设置如下

<Directory />
AllowOverride All
</Directory>

我在公共场合的 .htaccess 文件似乎可以正常工作,因为当我尝试以下类似操作时,我得到了重定向。还启用了 mod_rewrite:

<IfModule mod_rewrite.c>
Redirect 301 / https://google.com
...

感谢帮助

【问题讨论】:

    标签: apache .htaccess laravel


    【解决方案1】:

    尽管您的 document_root 已经指向公共子文件夹,但您要去http://lara.ci/public 对吗?

    【讨论】:

    • 你能访问lara.ci/index.php吗?您是否检查了文件的权限?
    • 我也无法访问。权限设置正确。
    【解决方案2】:

    问题在于您将文档根指向:

    DocumentRoot /var/www/lara.ci/public_html/public
    

    应该是:

    <VirtualHost *:80>
      ServerName www.lara.ci
      ServerAlias lara.ci
      DocumentRoot /var/www/lara.ci/public_html
      ErrorLog /var/www/lara.ci/error.log
      CustomLog /var/www/lara.ci/requests.log combined
    </VirtualHost>
    

    【讨论】:

    • 我不认为这就是问题所在。我已经按照你说的做了,但得到了同样的错误。在本地开发中,我像这样访问我的网址http://localhost/lara/public
    • 我收到消息“哎呀,好像出了点问题”。
    【解决方案3】:

    四处挖掘后,我意识到我的隐藏文件没有复制,例如 .env、.gitignore 等,因为我使用 cp 命令复制我的文件。为了解决这个问题,我运行了如下命令(来源:https://superuser.com/questions/61611/how-to-copy-with-cp-to-include-hidden-files-and-hidden-directories-and-their-con):

    cp -r /var/www/html/lara/.[^.]* /var/www/lara.ci/public_html 有效地复制了我所有的隐藏文件,并且一切正常。

    【讨论】:

      猜你喜欢
      • 2018-05-03
      • 1970-01-01
      • 1970-01-01
      • 2014-11-13
      • 2016-10-22
      • 2014-11-29
      • 1970-01-01
      • 2014-12-24
      • 2015-06-22
      相关资源
      最近更新 更多