我已经通过composer安装了一个全新的laravel 5.1。默认的预定义路由如下所示。
Route::get('/', function () {
return view('welcome');
});在按照Laravel 5.1的文档进行安装和基本配置之后,它可以很好地完成上面的路由。但当我将其更改为:
Route::get('test', function () {
return view('welcome');
});
or
Route::get('/test', function () {
return view('welcome');
}); 并试图通过以下方式访问同一页面:
http://localhost/mylaravel/public/test我得到了以下错误。
Not Found
The requested URL /mylaravel/public/test was not found on this server.它看起来像是路由不起作用。我已经启用了mod_rewrite,如下所示。
a2enmod rewrite
service apache2 restart我尝试了三种不同的.htaccess,如下所示。
# the defualt one
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# 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]
</IfModule>
# attempt two
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
# attempt three
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>它根本不起作用。我忘了配置什么了?如何解决这个路由问题?
发布于 2015-08-14 12:58:08
在这里的一些人的帮助下,我已经解决了这个问题,就像我做了以下事情一样。在命令行中。
sudo a2enmod rewrite
sudo service apache2 restart
sudo nano /etc/apache2/sites-available/000-default.conf找到DocumentRoot /var/www/html并直接在下面添加以下行:
<Directory "/var/www/html">
AllowOverride All
</Directory>并使用以下命令重新启动apache。
sudo service apache2 restart使用Laravel安装提供的默认.htaccess,它就可以正常工作。
发布于 2015-08-14 13:20:53
问题出在您的本地服务器正在运行。通过在控制台中运行以下命令来启动服务器:
php artisan serve --host=localhost --port=8080然后尝试通过此地址访问您的应用程序:
http://localhost:8080/test在laravel应用程序中,所有请求都是通过公共目录中的index.php文件接收的,当您请求类似于
http://localhost/mylaravel/public/test
然后服务器会认为你在请求静态文件。
https://stackoverflow.com/questions/32002071
复制相似问题