繁体   English   中英

Laravel在Apache虚拟主机的所有路由上显示404

[英]Laravel showing 404 on all routes in Apache virtual host

我有两个laravel应用,希望将它们放在实时Apache服务器上。 操作系统是CentO。 我遵循这个惯例来建立虚拟主机: 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
...

感激的帮助

是正确的,尽管您的document_root已经指向公共子文件夹,但您仍将转到http://lara.ci/public吗?

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

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>

深入研究后,我意识到我的隐藏文件没有被复制,例如.env,.gitignore等,因为我正在使用cp命令复制文件。 要解决此问题,我运行了如下命令(来源: https : //superuser.com/questions/61611/how-to-copy-with-cp-to-include-hidden-files-and-hidden-directories-和-他们的骗局 ):

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM