When laravel5.2 is transplanted to a new server, except for the '/' route, the pages corresponding to other routes display a 404 error (Object not found!)

WBOY
Release: 2016-08-04 09:21:23
Original
1153 people have browsed it

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 
Copy after login

注意:(/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 -MultiViews  RewriteEngine On # Redirect Trailing Slashes... RewriteRule ^(.*)/$ /$1 [L,R=301] # Handle Front Controller... RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ index.php [L] 
Copy after login

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 +FollowSymLinks RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ index.php [L] 
Copy after login

Nginx

若你使用了 Nginx,则可以在网站设置中增加以下设置:

location / { try_files $uri $uri/ /index.php?$query_string; }
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!