簡體   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