【发布时间】:2015-11-07 05:42:50
【问题描述】:
我已经通过 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>
它根本不起作用。我忘了配置什么?我该如何解决这个路由问题?
【问题讨论】:
-
你有本地服务器在运行吗?
-
是的,当我通过localhost/mylaravel/public 访问该页面时,我可以看到欢迎页面。
-
好的,正在检查。你的
.htaccess文件在哪里? -
试试这个
Route::get('/test', 'welcome'); -
@Stuart Wagner:我的 .htaccess 默认位于公共目录中。
标签: php .htaccess laravel routing laravel-5