Laravel Login with www. and without

2019-02-27 20:03发布

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条回答
三岁会撩人
2楼-- · 2019-02-27 20:58

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]
查看更多
登录 后发表回答