I have this rewrite code:
RewriteCond %{HTTP_USER_AGENT} ^.*iPhone.*$
RewriteRule ^(.*)$ http://stagingsite.com/site/mobile [R=301]
RewriteRule ^faq/$ /mobile/faq
The first line is working correctly. If the user is on an iphone then redirect to the mobile directory where the index page is displayed.
I also want users visiting:
http://stagingsite.com/site/faq
to get forwarded to http://stagingsite.com/site/mobile/faq if they’re on an iphone but the last line of code above doesn’t seem to be achieving this.
Any ideas what I have wrong?
RewriteConddirectives only get applied to the *immediately followingRewriteRule. So you have the condition that checks for iPhone, but that only gets applied to the redirect rule, and not the faq rule. You have to duplicate it:You should also include
Lflags so the 2 rules don’t accidentally interfere with each other. And your regex and target needs to be updated to accept an optional trailing slash and the subdirectory.