laravel5.2 移植到新伺服器上除了“/”路由 ,其它路由對應的頁面顯示報404錯誤(Object not found!)

來源:互聯網
上載者:User
1.伺服器系統:linux系統
2.Web環境:lamp(Linux+ Apache+Mysql+PHP)[使用的Linux版本的xampp軟體整合套件]
(1).不是storage和Bootstrap/cache檔案夾許可權問題。
(2).用laravel5.2做的項目在window系統本地端(wamp)測試其它頁面顯示可行。在Linux伺服器(lnmp)環境測試其它頁面也是可以顯示。

回複內容:

1.伺服器系統:linux系統
2.Web環境:lamp(Linux+Apache+Mysql+PHP)[使用的Linux版本的xampp軟體整合套件]
(1).不是storage和Bootstrap/cache檔案夾許可權問題。
(2).用laravel5.2做的項目在window系統本地端(wamp)測試其它頁面顯示可行。在Linux伺服器(lnmp)環境測試其它頁面也是可以顯示。

1.開啟 /etc/httpd/conf/httpd.conf(使用xampp: /opt/lampp/etc/httpd.conf).
2.確保DocumentRoot 指向的目錄是laravel中public檔案夾。如果不是需要改為如下:

DocumentRoot "/var/www/html/laravel/public/"    Allowoverride All

注意:(/var/www/html 是存放laravel目錄。 一般linux預設是/var/www/html目錄下,Xampp的是在/opt/lampp/htdocs/目錄下。 使用xampp上面/var/www/html/laravel/public/ 改為/opt/lampp/htdocs/laravel/public/)

3.確定laravel public目錄下.htaccess檔案有下面的代碼(如果沒有請將下面代碼添加進去):

Options -MultiViewsRewriteEngine On# Redirect Trailing Slashes...RewriteRule ^(.*)/$ /$1 [L,R=301]# Handle Front Controller...RewriteCond %{REQUEST_FILENAME} !-dRewriteCond %{REQUEST_FILENAME} !-fRewriteRule ^ index.php [L]

4.重啟Apache伺服器。sudo service httpd restart (使用 Xampp的 :
先關閉:/opt/lampp/lampp stop 再重啟:/opt/lampp/lampp start
詳細參考:http://stackoverflow.com/questions/21458080/the-requested-url-projectname-users-was-not-found-on-this-server-laravel/24354757#24354757

url重寫。

應該是URL重寫的問題

Apache

Laravel 架構通過 public/.htaccess 檔案來讓網址不需要 index.php。如果你的伺服器是使用 Apache,請確認是否有開啟 mod_rewrite 模組。
如果 Laravel 附帶的 .htaccess 檔案在 Apache 中無法使用的話,請嘗試下方的做法:

Options +FollowSymLinksRewriteEngine OnRewriteCond %{REQUEST_FILENAME} !-dRewriteCond %{REQUEST_FILENAME} !-fRewriteRule ^ index.php [L]

Nginx

若你使用了 Nginx,則可以在網站設定中增加以下設定:

location / {    try_files $uri $uri/ /index.php?$query_string;}
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.