Get the solution ↓↓↓
...where i can put special redirect with variable if user are desktop?
RewriteRule ^(.*)$ https://desktop.othersomesite.com/$1 [R=301,L]
It looks like you can just put it immediately after your existing directives (that redirects to the mobile site).
something like this
<?php
I'm not quite sure what you are trying to show here, other than perhaps trying to show the logic? But this would seem to be misleading since I don't believe you want to implement this in PHP; do you? The PHP is also invalid (crucially using the assignment operator, instead of checking for equality).
However, some notes regarding your existing directives...
RewriteCond %{QUERY_STRING} (^|&)mobile=1(&|$) RewriteRule ^ - [CO=mobile:1:%{HTTP_HOST}] RewriteCond %{QUERY_STRING} (^|&)mobile=0(&|$) RewriteRule ^ - [CO=mobile:0:%{HTTP_HOST}] RewriteCond %{QUERY_STRING} (^|&)mobile=0(&|$) RewriteRule ^ - [S=1] RewriteCond %{HTTP:x-wap-profile} !^$ [OR] RewriteCond %{HTTP_USER_AGENT} "android|blackberry|ipad|iphone|ipod|iemobile|opera mobile|palmos|webos|googlebot-mobile" [NC,OR] RewriteCond %{HTTP:Profile} !^$ RewriteCond %{HTTP_HOST} !^m\. RewriteCond %{HTTP:Cookie} !\mobile=0(;|$) RewriteRule ^(.*)$ https://m.somesite.com/$1 [R=301,L]
The first two rules (that set themobile cookie) can be combined into one. The third rule can be converted into a singleRewriteCond directive on the main rule that follows.
There is aHTTP_COOKIE server variable, so I would tend to use this instead ofHTTP:Cookie (to access the header directly). The\m in the last CondPattern looks like an error - although this still matches a literalm, so it "works". However, this also matches any cookie whose name ends with "mobile", not justmobile. The regex needs to something like(^|;|\s)mobile=0(;|$) instead, since cookie name=value pairs are often delimited by;<space>.
So, bringing these points together we have:
# Set mobile cookie if mobile present in query string
RewriteCond %{QUERY_STRING} (?:^|&)mobile=(0|1)(?:&|$)
RewriteRule ^ - [CO=mobile:%1:%{HTTP_HOST}]
# Mobile
RewriteCond %{HTTP:x-wap-profile} !^$ [OR]
RewriteCond %{HTTP_USER_AGENT} "android|blackberry|ipad|iphone|ipod|iemobile|opera mobile|palmos|webos|googlebot-mobile" [NC,OR]
RewriteCond %{HTTP:Profile} !^$
RewriteCond %{HTTP_HOST} !^m\.
RewriteCond %{QUERY_STRING} !(^|&)mobile=0(&|$)
RewriteCond %{HTTP_COOKIE} !(^|;|\s)mobile=0(;|$)
RewriteRule (.*) https://m.somesite.com/$1 [R=301,L]
# Else Desktop
RewriteRule (.*) https://desktop.othersomesite.com/$1 [R=301,L]
Also, since you are potentially basing the redirect on theUser-Agent andCookie headers, these should also be added to theVary header to ensure proper caching from any intermediaries. For example, add the following after the above:
Header always merge Vary "User-Agent, Cookie"
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Find the answer in similar questions on our website.
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.
PHP (from the English Hypertext Preprocessor - hypertext preprocessor) is a scripting programming language for developing web applications. Supported by most hosting providers, it is one of the most popular tools for creating dynamic websites.
The PHP scripting language has gained wide popularity due to its processing speed, simplicity, cross-platform, functionality and distribution of source codes under its own license.
https://www.php.net/
Welcome to the Q&A site for web developers. Here you can ask a question about the problem you are facing and get answers from other experts. We have created a user-friendly interface so that you can quickly and free of charge ask a question about a web programming problem. We also invite other experts to join our community and help other members who ask questions. In addition, you can use our search for questions with a solution.
Ask about the real problem you are facing. Describe in detail what you are doing and what you want to achieve.
Our goal is to create a strong community in which everyone will support each other. If you find a question and know the answer to it, help others with your knowledge.