B
B
BelarusOK2019-08-29 06:12:45
PHP
BelarusOK, 2019-08-29 06:12:45

How to change links when redirecting to mobile version?

There is a redirect code for the mobile version:

//-----------------------------------------------
// MOBILE DETECT + COOKIE
//-----------------------------------------------

if( isset($_GET['nomobile']) ){
setcookie('nomobile','1',time()+3600*24,'/');
$_COOKIE['nomobile'] = 1;
}
define('NOMOBILE',isset($_COOKIE['nomobile']));

require_once 'Mobile_Detect.php';
$detect = new Mobile_Detect();
if(!NOMOBILE and ($detect->isMobile() or $detect->isTablet())){
   header("Location: ".'https://'.$_SERVER['HTTP_HOST'].'/lofiversion/');
 }
   
exit();
}

When accessing any page from a mobile phone, it redirects to /lofiversion/
I have the following links - the
usual one: /forum67.html | mobile /lofiversion/?f67.html
and
desktop: topic51311.html | mobile lofiversion/?t51311.html
Is it possible and how to correctly specify a redirect to the place we need - a section or a topic?
Or via .htaccess ?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
dodo512, 2019-08-29
@BelarusOK

$u = preg_replace('~^/(?|(f)orum|(t)opic)(?=\d+\.html)~', '\\1', $_SERVER['REQUEST_URI']);
header('Location: https://'.$_SERVER['HTTP_HOST'].'/lofiversion/?'.$u);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question