我在使用Laravel 5.3时遇到了一个奇怪的问题(至少对我而言)。 我尝试通过会话获取上一个链接(在用户登录之前),并在他们成功登录后将其重定向回此链接。
我使用这行代码放入会话:
Session::put('url.intended', $link);
我使用这行代码从会话中获取:
Session::get('url.intended', url('/'));
当我在开发中运行并从会话中读取时,我将此url作为url.intended:
http://example.test/profile/data?_url=%2Fprofile%2Fdata
使用此网址,重定向在登录后正常工作!
现在,当我处于生产模式(AWS,ELB,NGINX)时,我将此网址设为url.intended:
https://example.org/profile/data
没有?_url =%2Fprofile%2Fdata所以不起作用并重定向到主页。
这是Laravel 5.3问题还是负载均衡器和nginx设置错误?
nginx配置:
server {
listen 80;
server_name example.org;
rewrite ^/(.*)$ https://www.$host$request_uri redirect;
}
server {
listen 80;
root /var/www/public;
index index.php index.html index.htm;
server_name www.example.org;
if (!-e $request_filename) {
rewrite ^.*$ /index.php last;
}
if ($http_x_forwarded_proto = http) {
return 301 https://$server_name$request_uri;
}
location / {
sendfile off;
try_files $uri $uri/ /index.php?_url=$uri&$args;
}
location ~ \.php$ {
try_files $uri = 404;
fastcgi_pass phpfpm:9000;
fastcgi_index /index.php;
include fastcgi_params;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
我的设置有问题或者laravel中有什么东西可以做,而不是从url.intended中删除?_url?
答案 0 :(得分:0)
如果你使用Laravel 5.3:
修改新的中间件身份验证重定向程序
/app/Http/Middleware/RedirectIfAuthenticated.php
将句柄功能更改为:
public function handle($request, Closure $next, $guard = null)
{
if (Auth::guard($guard)->check()) {
return redirect()->intended('/home');
}
return $next($request);
}