У меня есть приличное рабочее решение для перенаправления мобильных/настольных компьютеров с помощью кода .htaccess ниже, но есть еще несколько улучшений, которые могли бы сделать его окончательным, если кто-то может помочь.
Настройка каталога:
Ссылки с поддержкой куки:
Текущий файл .htaccess:
RewriteEngine on
# Check if this is the desktop to mobile query string
RewriteCond %{QUERY_STRING} (^|&)m=1(&|$)
# Set a cookie, and skip the next 2 rules
RewriteRule ^ - [CO=mredir:1:%{HTTP_HOST},S=2]
# Check if this is the mobile to desktop query string
RewriteCond %{QUERY_STRING} (^|&)m=0(&|$)
# Set a cookie, and skip the next rule
RewriteRule ^ - [CO=mredir:0:%{HTTP_HOST},S]
RewriteCond %{HTTP_USER_AGENT} "android|blackberry|iphone|ipod|iemobile|opera mobile|palmos|webos|googlebot-mobile" [NC]
# Check if we're not already on the mobile site
RewriteCond %{HTTP_HOST} !^m\.
# Can not read and write cookie in same request, must duplicate condition
RewriteCond %{QUERY_STRING} !(^|&)m=0(&|$)
# Check to make sure we haven't set the cookie before
RewriteCond %{HTTP_COOKIE} !^.*mredir=0.*$ [NC]
RewriteRule ^(.*)$ http://m.website.com/ [L,R=302]
То, что я хочу добавить:
Также, если кто-то заметит какие-либо ошибки или улучшения в текущем коде, буду рад услышать это!