I have the following scenario:
I have two websites, one for mobile (m.mydomain.com) and one for desktop (mydomain.com)
I decide which site to load using user agent detection
- Once this detection happened, I keep the user's device information in a cookie called: device.
- This cookie can contain one of the following values: desktop or mobile.
- If the user comes to the site with a device cookie, I skip the user agent detection and I assume that the user is really using the device what is written in the cookie.
(Note to the image: It works the opposite direction as well, when the user wants to open a mobile link from desktop. When the mobile site sets the cookie, the cookie domain will be m.mydomain.com)
The error: So most of the times this mechanism is in sync but still sometimes I experience redirect loops, and I don't really understand the reason of that. Basically one domain thinks that it is desktop, the another thinks it is mobile and they play an infinite loop with the redirection. After 3 redirects the browser crashes with too many redirects error.
It is also important to mention that I never experienced this on a real mobile device, only when I was switching in the chrome inspector between mobile and desktop user agents.
My ideas were that:
- Perhaps the cookie setting failed before the redirect
- Perhaps the domain naming causes confusion somehow when I want to access the value.
- Perhaps reading the cookie value fails