Laravel使用www登录.没有 [英] Laravel Login with www. and without

查看:66
本文介绍了Laravel使用www登录.没有的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用NGINX在Ubuntu 14.04上创建的Laravel 5.4应用程序,它可以在 https://MyDomain.TLD <上正常运行/a>和 https://www.MyDomain.TLD

I have a Laravel 5.4 App I created on a Ubuntu 14.04 with NGINX and it runs fine on https://MyDomain.TLD and https://www.MyDomain.TLD

问题是:当我登录一个(无论是否带有www)时,它都可以正常工作,但是cookie信息没有共享给另一个变体.

The problem is: When I log in either(with or without www), it works fine but cookie informations are not shared to the other variant.

在Laravel 5+的早期版本中,我对此没有任何问题.

I did not have an issue with this in previous versions of Laravel 5+ .

有指针吗?

推荐答案

您需要处理www,因为会话是基于域保存的,因此请尝试将以下代码添加到.htaccess文件中,其中一个用于强制重定向到www,另一个用于强制重定向到www是删除www.

You need to handle www because session is saving based on domain, so try adding below code into .htaccess file, one is for force redirection to www and one is to remove www.

#Force www:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301,NC]

#Force non-www:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.example\.com [NC]
RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]

这篇关于Laravel使用www登录.没有的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆