the code looks like this basically the index.php on root folder have to check users device whether its on desktop or mobile, if its on mobile then it’ll be redirected to /mobile and use the index.php on mobile directory. Well apparently this causes infinite loop i guess (?), but the issue is only on the production server, while on my local machine/laptop its working flawlessly.
root index.php
$detect = new Mobile_Detect();
$uri = $_SERVER['REQUEST_URI'];
$normalizedUri = preg_replace('#(/mobile)+#', '/mobile', $uri);
if ($detect->isMobile()) {
if (strpos($normalizedUri, '/mobile') === 0) {
header('Location: ' . $normalizedUri);
die;
} else {
header('Location: /mobile' . $normalizedUri);
die;
}
}
/mobile/index.php
$detect = new Mobile_Detect();
$uri = str_replace("/mobile", "", $_SERVER['REQUEST_URI']);
if (!$detect->isMobile()) {
header('Location: ' . $uri);
exit(0);
}
and the only page that work is index.html (home)
what i’ve tried so far was to normalized the uri, because it used to spam the uri that look like http://example.com/mobile/mobile/mobile/mobile and so go on while it should be http://example.com/mobile so i wrote this code
root index.php
$normalizedUri = preg_replace('#(/mobile)+#', '/mobile', $uri);
root index.php
if (strpos($normalizedUri, '/mobile') === 0) {
header('Location: ' . $normalizedUri);
die;
} else {
header('Location: /mobile' . $normalizedUri);
die;
}
Azka is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.