I tried this on many of my websites, most of them are getting "redirect you too many times" error, and I compare server settings of those that work and don't, but couldn't find any major difference other than working one is hosting with PHP5.6 and non-working one PHP7. So has anyone encountered this and what could be causing the problem?
I think this is caused by the way you have configured your sites.
My guess is that in those sites that you are getting the too many redirects, the User Login form is loaded from the home page menu item - which is already set its access to registered users.
So, the location which Joomla is trying to redirect you, is also registered, thus Joomla will try again and again to redirect you, and that's causes the redirect loop.
In this case, you need to make sure that there is a menu item for the User Login, that is set to Public Access and that the login-redirect URL that Joomla forwards you is not using the home-page menu item - or any other menu item that is also set to non-public access.
Note that if you are using SEF components e.g. sh404SEF, the Login-URL might have been stored in the database using another menu-itemId than the one you want, so in this case you will have to update it, to use the correct one.