是的,有类似的问题,但建议的解决方案对我不起作用。 所以我设置了 Laravel,安装工作正常。 好吧,只要我留在基本路线上
localhost/page/
一旦我尝试走我的路线之一,比方说
localhost/page/subpage
并且路由被配置为返回一个 View
Route::get('subpage', ['as' => 'subpage', 'uses' => 'GenericPageController@subpage']);
Controller 中的subpage
方法:
public function subpage()
{
return view('base.subpage');
}
每当我尝试访问其中一条路线时,我只会从服务器收到 404 响应。无论我使用什么 Controller ,或者它是否返回 View 或闭包,都没有关系。
- mod_rewrite 已启用
- 在主目录上设置了
AllowOverride
到全部
我在 page/public
文件夹中的 .htaccess
如下所示:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteBase /
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
有人知道问题出在哪里吗?
最佳答案
.htaccess
文件不会加载,因为它位于 public
目录中,该目录实际上是您的文档根目录。因此,您应该通过转到 localhost/page/public/subpage
来访问该应用。
如果你想使用 localhost/page/subpage
同时保持你的目录结构完整,那么你需要添加一个新的 .htaccess
文件到 page
目录,并从 public
目录中删除 .htaccess
文件。
/page/.htaccess
内容:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteBase /page/
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Send requests to public directory...
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ public/index.php [L]
</IfModule>
不幸的是,由于 Laravel 获取请求信息的方式,您需要在路由配置中将路由分组到 page
目录:
Route::group(['prefix' => 'page'], function()
{
Route::get('subpage', ['as' => 'subpage', 'uses' => 'GenericPageController@subpage']);
// Your other routes ...
});
基本上,在我看来,这是解决此问题的最简单方法。您还可以将 public
目录的内容上移一级,并相应地更改引导文件中的路径。
关于apache - Laravel 5 Apache mod_rewrite 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31227667/