-1

1- I need the .htaccess code for this condition If the user clicked on: website1.download OR website2.download It redirects the user depending on his OS for example:

2- I've more than one website in my host and I need to create a one .htaccess to all websites in the host, where I can create the .htaccess file?

That is the htaccess codes and it's not working:

<If "req('Host') = 'website1.download' && = 'website2.download'">
    # turn on rewrite engine
    RewriteEngine on

    # only detect smart phone devices if we are not on mobile site
    # to prevent redirect looping
    RewriteCond %{HTTP_HOST} !^https://google.com/$

    # Android
    RewriteCond %{HTTP_USER_AGENT} "android" [NC]
    # redirect to google play
    RewriteRule .? https://play.google.com/store%{REQUEST_URI}  [L,R=302]

    # iOS
    RewriteCond %{HTTP_USER_AGENT} "android" [NC]
    # redirect to app store
    RewriteRule .? https://www.apple.com/ios/app-store/%{REQUEST_URI}  [L,R=302]
</If>
M-Tharwat
  • 1
  • 2

1 Answers1

0

Okay, I'm going with example.com and example.net since that's what they are for. Also, I'm assuming these domains point to your server and they have all been bound to it, too. Lastly, I'm assuming you have a pattern already for device detection? It isn't super clear in your question. (If you don't you can probably just base this off Google and this thread.)

You can just stack RewriteCond and join them with an OR

RewriteCond %{HTTP_HOST} example.com [NC,OR]
RewriteCond %{HTTP_HOST} example.net [NC]
RewriteCond %{HTTP_USER_AGENT} "android" [NC]
RewriteRule .? https://play.google.com/store%{REQUEST_URI}  [L,R=302]

Technically that is a regex, too, so some care should be taken for special characters as well as being more specific, adding subdomain support and just merging everything into a single condition.

RewriteCond %{HTTP_HOST} ^(www\.)?example\.(com|net)$ [NC]
RewriteCond %{HTTP_USER_AGENT} "android" [NC]
RewriteRule .? https://play.google.com/store%{REQUEST_URI}  [L,R=302]

There's HTTP_HOST vs SERVER_NAME that you should be aware of, too.

All that said, I can't think of a good reason to do this. From an SEO-perspective, you are going to wind up hiding 2 out of 3 redirects because spiders store information they find at a given URL, and if that changes, the most recent change wins. From a user-perspective, people are mostly trained to click the badges from the stores, I wouldn't introduce something new and weird. If you are trying to track a click, I'd just use JS.

Chris Haas
  • 53,986
  • 12
  • 141
  • 274