I’ve seen people redirect iPhone users by using this:
RewriteCond %{HTTP_USER_AGENT} iPhone
RewriteCond %{REQUEST_URI} !^/my-iPhone-site/
RewriteRule .* /my-iPhone-site/ [R]
But how could I make a webpage only accessible with a specific user agent? Instead of blacklisting iPhones, I would like to whitelist them, for example.
Let me know!
2
Answers
@MrWhite's answer didn't work for some reason, but this was how I figured it out.
This will take all non iPhone users to 403.
To only allow requests to
/my-iPhone-site/...
from user-agents that containiPhone
then you could do something like the following using mod_rewrite in.htaccess
(near the top):This blocks (403 Forbidden) any user that tries to access
/my-iPhone-site/...
that does not containiPhone
in the user-agent string.The
!
prefix on the CondPattern negates the regex. So, in this example, it is successful when theHTTP_USER_AGENT
server variable does not contain the string “iPhone”.If you wanted to redirect such users instead then change the
RewriteRule
to read:NB: You should use the
L
flag when redirecting, otherwise processing continues through your file.