【问题标题】:Laravel keeps responding with redirectsLaravel 不断响应重定向
【发布时间】:2015-12-13 13:24:55
【问题描述】:

我正在使用 Laravel 5(API,后端)和 AngularJS(前端)开发一个项目。我的应用程序有一个前端和一个管理部分(如下面的文件结构所示)。我可以正常访问前端,但似乎无法访问管理部分的主页。我不断收到消息说这个页面在 chrome 中有很多重定向。

我所有的 html 视图和 js/css/assets 都在各自文件夹下的 public 文件夹中

这是我在 laravel 公用文件夹中的结构

+---admin
|   +---dist
|   +---src
|   index.html
+---assets
+---bower_components
+---frontend
    +---dist
    +---src
    index.html

Laravel Routes.php

//Show Frontend Index.html
Route::get('/', function () {
    return File::get(public_path() . '/frontend/index.html');
});

//Show Admin Index.html
Route::get('/admin', function () {
    return File::get(public_path() . '/admin/index.html');
});



Route::group(['prefix' => 'api'], function () {
   //API'routes go here
});

我可以在前端访问我的 index.html(目前只是一个单页网站),它工作正常。但是在尝试访问我的管理员 index.html 时,我无法弄清楚重定向循环问题。我不知道我是否犯了一个菜鸟错误,但任何帮助都非常感激

【问题讨论】:

  • 你为什么要return File::get而不是使用正确的视图?这是一个非常奇怪的代码,错过了 Laravel 的重点。如果您只是让它们从public 目录提供 HTML,那么您根本不需要这些路由 - 您的网络服务器会处理这些。

标签: php angularjs laravel-5


【解决方案1】:

也许问题出在路径/admin/index.html 落入/admin 路由规则中,导致循环。也许在这种情况下,您需要的是 htaccess 重定向?像这样: 重定向 301 /admin /admin/index.html

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-07-12
    • 2016-07-20
    • 2022-11-25
    • 2019-07-22
    • 1970-01-01
    • 1970-01-01
    • 2019-09-20
    • 2011-08-19
    相关资源
    最近更新 更多