【问题标题】:Laravel 4.2 application occurs unnecessary redirection after uploading live serverLaravel 4.2 应用程序在上传实时服务器后发生不必要的重定向
【发布时间】:2016-03-20 20:28:18
【问题描述】:

我的 laravel(4.2) 应用程序在 localhost(xampp) 上运行良好。但是在尝试登录时上传到实时服务器后,它会显示一个空白页面,并显示一条消息“重定向到我的主页 url”。它还会引发登录错误

对不起我的英语不好。请帮我。我在下面附上了我的 htaccess:

<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
    Options -MultiViews
</IfModule>

RewriteEngine On

# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]

# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

这是我的控制器功能。

public function adminLoginCheck() {
$validation_rule = array(
    'username' => array('required', 'min:5', 'max:50'),
    'password' => array('required', 'min:6', 'max:50')
);
$validation = Validator::make(Input::all(), $validation_rule);
// Validation Check
if ($validation->fails()) {
    return Redirect::to('/')->withErrors($validation);
} // After Validation Authentication start
else {
    $athentication = Auth::attempt(array('username' => Input :: get('username'), 'password' => Input :: get('password')));
    // When Authentication True
    if ($athentication) { 
        $rememberme = Input::get('remember');
        if(!empty($rememberme)){
            //Remember Login data
           Auth::loginUsingId(Auth::user()->id,true);
        }
        //Redrict to the Target page
        return Redirect::intended('adminDashboard');
    } else {
        //Redrict Login Form with Authentication error massege.
        return Redirect::to('/')->with('authentication_error', 'Username or Password is not valid!');
    }
}

}

我的 Auth 过滤器如下所示:

Route::filter('auth', function(){if (Auth::guest()){
if (Request::ajax())
{
    return Response::make('Unauthorized', 401);
}
else
{
    return Redirect::guest('login');
}  }  })

所有刀片模板都可用。我不明白为什么会出现带有重定向消息的空白页面。即使在不输入的情况下提交登录

用户名和密码 这是直播网址http://noveltyshop.tech-novelty.com/ 用户:管理员密码:通过

我的路线:

Route::get('/', array('as' => 'admin', 'uses' => 'UsersController@adminLoginForm'));
Route::post('/login', array('as' => 'login', 'uses' => 'UsersController@adminLoginCheck'));
Route::get('/adminDashboard', array('as' => 'adminDashboard', 'uses' => 'UsersController@adminDashboard')); 
Route::get('/logout', array('as' => 'logout', 'uses' => 'UsersController@getLogOut')); 
Route::get('/updateUserProfileForm', array('as' => 'updateUserProfileForm', 'uses' => 'UsersController@updateUserProfileForm'));
Route::post('/updateUserProfile', array('as' => 'updateUserProfile', 'uses' => 'UsersController@updateUserProfile')); 

UsersController@adminDashboard

public function adminDashboard() {
    return View::make('admin.pages.admin_dashboard')->with('title', 'AdminDashboard');
}

【问题讨论】:

  • 你能更新你的路由和控制器吗?
  • 是的,我正在更新我的路线。
  • 删除我的评论后,这仍然显示给我。为什么?
  • 只有你才能看到这个答案..不用担心;)
  • 好的,为了测试,您可以将admin_dashboard.blade.php 文件放在views 文件夹中,然后更改为return View::make('admin_dashboard')-&gt;with('title', 'AdminDashboard'); 并告诉您会发生什么吗?

标签: .htaccess laravel laravel-4 url-redirection laravel-routing


【解决方案1】:

当你使用 Laravel 4.2 时

您应在 Controller 中处理此问题。

这是我们处理的默认方式

if (Auth::attempt(['email' => $email, 'password' => $password])) {
    return Redirect::intended('yourTargetPageAfterLogin');
}

在 auth 过滤器中你应该有这个

Route::filter('auth', function() {
    if (Auth::guest()) {
        return Redirect::guest('login');
    }
});

注意:确保您拥有控制器中定义的刀片

建议:为什么不将upgrade 改为5.1

【讨论】:

    猜你喜欢
    • 2015-03-14
    • 2015-08-19
    • 1970-01-01
    • 2013-05-28
    • 2011-01-14
    • 2017-08-29
    • 2022-08-02
    • 2015-08-04
    • 1970-01-01
    相关资源
    最近更新 更多