Laravel Login with www. and without

会有一股神秘感。 提交于 2019-12-20 05:18:08

问题


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

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.

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

Any pointers?


回答1:


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]


来源:https://stackoverflow.com/questions/44158080/laravel-login-with-www-and-without

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!