[英]Laravel 5.4 - Routes not working
我已经安装了全新的ubuntu mini安装并安装了apache2和PHP。 (还使用最新的稳定版ubuntu进行了尝试)我还安装了一些模块,其中包括laravel安装文档中列出的模块 :
OpenSSL PHP Extension
PDO PHP Extension
Tokenizer PHP Extension
Mbstring PHP Extension
XML PHP Extension
我还安装了:
libapache2-mod-php , git和curl,php-curl :
sudo apt-get install libapache2-mod-php
sudo apt-get install curl
sudo apt-get install php-curl
sudo apt-get install git
现在,我从Windows的apache服务器复制了整个laravel项目。 然后我执行
chmod 775 -R *
和
chown www-data:www-data -R *
但是,路线不起作用。
例如http://192.168.2.100/selenium/public/start
应该显示我的起始页,而不是我得到:
找不到:在此服务器上找不到请求的URL / selenium / public / start。
所以,我研究,发现这对计算器。
从答案:
Try to navigate to your expected route prepend it with /index.php/, in your case: http://localhost/laravel/index.php/users. If it works (no 404) then you problem is with the Rewrite Module configuration of Apache HTTP, you should follow the next steps.
所以我试图像建议的那样调用我的页面:
http://192.168.2.100/selenium/public/index.php/start
那行得通。 因此,重写模块配置存在问题。
他/她建议在public/.htaccess
RewriteEngine On
行下添加RewriteBase /directory/
所以我将public/.htaccess
更改为此,然后重新启动apache2:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteBase /selenium/
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
但是,这些路线仍然无法使用。 我还能尝试什么?
Apache版本:
Server version: Apache/2.4.7 (Ubuntu) Server built: Jul 15 2016 15:32:47
PHP版本:
PHP 7.0.16-4+deb.sury.org~trusty+1 (cli) (built: Mar 2 2017 13:50:00) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
with Zend OPcache v7.0.16-4+deb.sury.org~trusty+1, Copyright (c) 1999-2017, by Zend Technologies
Linux版本:
Linux linux 3.13.0-110-generic#157-Ubuntu SMP Mon Feb 20 11:55:25 UTC 2017 i686 i686 i686 GNU / Linux
很多时候,如果是全新安装的Ubuntu,并且您安装了apache,则默认情况下不会启用rewrite
模块。 在终端中运行以下命令
sudo a2enmod rewrite
sudo service apache2 restart
现在,由于启用了重写模块,将从laravel项目的公共文件夹中读取.htaccess
,并且路由将按预期工作。
我不必在laravel中更改默认.htaccess文件中的任何行。
希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.