Redirect: Automatic redirect for my website

General Tech Bugs & Fixes 2 years ago

0 1 0 0 0 tuteeHUB earn credit +10 pts

5 Star Rating 1 Rating

Posted on 16 Aug 2022, this text provides information on Bugs & Fixes related to General Tech. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.

Take Quiz To Earn Credits!

Turn Your Knowledge into Earnings.

tuteehub_quiz

Answers (1)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer Best Answer 2 years ago

I need help for an automatic redirect. I need an auto redirect to https with www, mobile device without www and language detect:

 

1.https with www 2.on mobile devices to https://m.example.com/ 3.auto detect language to https://www.example.com/en/ or /el/ or /ru/ Mobile device https://m.example.com/en/ or /el/ or /ru/

 

This my .htaccess file

 

Options -Indexes

AddDefaultCharset utf-8

 

ErrorDocument 402 /404.php

ErrorDocument 403 /404.php

ErrorDocument 404 /404.php

ErrorDocument 500 /404.php

ErrorDocument 501 /404.php

ErrorDocument 502 /404.php

 

DirectoryIndex index.php

 

RewriteEngine on

 

RewriteCond %{HTTP_HOST} ^example\.com [NC]

RewriteCond %{SERVER_PORT} 80 

 

RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]

 

#RewriteCond %{HTTP:Accept-Language} ^en [NC]

#RewriteRule ^$ /[L,R=301]

 

#RewriteCond %{HTTP:Accept-Language} ^el [NC]

#RewriteRule ^$ /el/ [L,R=301]

 

#RewriteCond %{HTTP:Accept-Language} ^ru [NC]

#RewriteRule ^$ /ru/ [L,R=301]

 

RewriteBase /

 

RewriteRule ^/$ index.php [L,QSA]

RewriteRule ^ru/(.*)$ /$1?lang=ru [L,QSA]

RewriteRule ^en/(.*)$ /$1?lang=en [L,QSA]

RewriteRule ^el/(.*)$ /$1?lang=el [L,QSA]

RewriteRule ^ajax/(.*)$ /$1?mode=ajax [L,QSA]

RewriteRule ^robots.txt$ misc.php?controller=robots [L,QSA]

RewriteRule ^image/([0-9]+)x([0-9]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+).jpg$ resize.php?apid=$3&key=$4&w=$1&h=$2 [L,QSA]

RewriteRule ^attachment/([a-zA-Z0-9]+)/([0-9]+)/(.*)$ attachment.php?dmuid=$1&order=$2&original=$3 [L,QSA]

RewriteRule ^item/print/([a-zA-Z0-9_-]+)_([0-9]+)$ item.php?mode=print&controller=item&id=$2 [L,QSA]

RewriteRule ^item/([a-zA-Z0-9_-]+)_([0-9]+)$ item.php?controller=item&id=$2 [L,QSA]

RewriteRule ^moderation/list/(waiting|inactive|moderated)/$ moderation_list.php?controller=$1 [L,QSA]

RewriteRule ^my/(waiting|inactive|moderated)/$ my.php?controller=$1 [L,QSA]

RewriteRule ^my/message/([0-9]+)$ my_messages.php?controller=message&mid=$1 [L,QSA]

RewriteRule ^my/messages/([0-9]+)$ my_messages.php?controller=messages&aid=$1 [L,QSA]

RewriteRule ^my/messages/(sent|archive)/$ my_messages.php?controller=$1 [L,QSA]

RewriteRule ^pay/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/$ gateway.php?controller=gateway&code=$1&action=$2 [L,QSA]

RewriteRule ^pay/([a-zA-Z0-9_-]+)/$ pay.php?controller=$1 [L,QSA]

RewriteRule ^s-login/([a-zA-Z0-9_-]+)/$ /s-login.php?provider=$1 [L,QSA]

RewriteRule ^list/$ list.php?controller=list&query=list [L,QSA]

RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/$ list.php?controller=list&query=$1/$2/$3/$4 [L,QSA]

RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/$ list.php?controller=list&query=$1/$2/$3 [L,QSA]

RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/$ list.php?controller=list&query=$1/$2 [L,QSA]

RewriteRule ^([a-zA-Z0-9_-]+)/$ list.php?controller=list&query=$1 [L,QSA]

and those are my php fuctions :

 

 $config['siteurl'] = !empty($_SERVER['HTTP_HOST'])?$_SERVER['HTTP_HOST']:'';

$config['mobileurl'] = 'example.com';

 

$config['langs'] = array('en', 'el', 'ru',);

$config['lang_names'] = array('en' => 'EN', 'el' => 'EL', 'ru' => 'RU');

if(isset($_GET['lang']) && !empty($_GET['lang'])) {

    if (!in_array(trim($_GET['lang']), $config['langs'])) {

        $config['lang'] = reset($config['langs']);

    } else {

        $config['lang'] = trim($_GET['lang']);

    }

}

else {

    $config['lang'] = $config['langs'][0];

}

 

unset($_GET['lang']);

if ($config['lang'] != reset($config['langs'])) {

    $langPrefix = '/' . $config['lang'];

} else {

    $langPrefix = '';

}

 

include "includes/mobiledetect/Mobile_Detect.php";

if (isset($_GET['force_mobile']) && trim($_GET['force_mobile']) == '0' && !empty($_GET['force_mobile'])) {

    setcookie('force_mobile', '0', $time + 60 * 60 * 24 * 365, '/', '.' . $config['siteurl']);

    header('Location: https://' . $config['siteurl'] . trim($_GET['ref']));

    exit;

}

$mdetect = new Mobile_Detect;

if ($mdetect->isMobile() && !$mdetect->isTablet()) {

    if (!$m) {

        if (!isset($_COOKIE['force_mobile']) || trim($_COOKIE['force_mobile']) == '1') {

            setcookie('force_mobile', '1', $time + 60 * 60 * 24 * 365, '/', '.' . $config['siteurl']);

            //header('Location: https://m.' . $config['siteurl'] . $langPrefix . $_SERVER['REQUEST_URI']);

            header('Location: https://m.' . $config['mobileurl'] . $langPrefix . $_SERVER['REQUEST_URI']);

No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.