0

I need to auto open page in chrome. This code opens in mobile chrome without any problems.

RedirectMatch 301 id/(.*)$ intent://remoteurl.com/cancel.php?id=$1#Intent;scheme=https;package=com.android.chrome;end 

But need this work only if user is on Android. So I have tried this but it doesnt redirect.

RewriteCond %{HTTP_USER_AGENT} (android) [NC] RedirectMatch 301 ^id/(.*)$ intent://remoteurl.com/cancel.php?id=$1#Intent;scheme=https;package=com.android.chrome;end 

The problem is, this url scheme won't work if RewriteRule is used,

RewriteRule ^i/(.*)$ intent://remoteurl.com/cancel.php?id=$1#Intent;scheme=https;package=com.android.chrome;end [R=301,L] 

but works with redirectMatch 301. However, redirectMatch 301 doesn't work if RewriteCond is used. So what is the correct way to do that ?

(Similar questions have already been asked, however this is for different url scheme intent://)

1 Answer 1

1

You can use the one of the following code for redirecting the user if he is visiting from mobile ....

Using PHP:

<?php function isMobile() { return preg_match("/(android|avantgo|blackberry|bolt|boost|cricket|docomo|fone|hiptop|mini|mobi|palm|phone|pie|tablet|up\.browser|up\.link|webos|wos)/i", $_SERVER["HTTP_USER_AGENT"]); } // If the user is on a mobile device, redirect them if(isMobile()) { // Redirect to Some where .... header("Location: http://m.yoursite.com/"); } ?> 

Using .htaccess:

  • Code 1
RewriteEngine on RewriteCond %{HTTP_USER_AGENT} (iphone|ipad|android|blackberry|windows\ phone) [NC] RewriteCond %{HTTP_HOST} ^\.m.yoursite.com\.com$ [NC] RewriteRule ^ http://yoursite.com 
  • Code 2
RewriteEngine on RewriteCond %{HTTP_USER_AGENT} !(iphone|ipad|android|blackberry|windows\ phone) [NC] RewriteCond %{HTTP_HOST} ^m\.yoursite\.com$ [NC] RewriteRule ^ http://www.yoursite.com 
Sign up to request clarification or add additional context in comments.

4 Comments

Thanks. But I know these already, have you tried "intent://" url in RewriteRule ? It doesn't work somehow.
Forgot to add, the the redirect url is external.
Update: php header redirect is working with "intent://" so it solved my problem, thanks!
Great. Good Luck.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.