.htaccess Redirect to specific Sub-Domain based on User Agent

/ By Arjun / Published on July 9, 2017

You can use mod_rewrite’s RewriteCond directive to redirect user’s to different websites depending on what device they are using.

.htaccess Rules

Following rewrite rules will redirect iphone, ipad and ipod users to different sub domains based on the user agent.

For all the other user agent requests, default rewrite rules will be applied.

I hope you like this Post, Please feel free to comment below, your suggestion and problems if you face - we are here to solve your problems.

0 0 votes
Article Rating
Subscribe
Notify of
guest
4 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Budi Frankie Gozhali
3 years ago

hi arjun, thank for this code, I have question how if I like to redirect user agent from specified urls to specified urls too (not root domain only).

thanks for suggestion

arjun
3 years ago

just use Redirect Directive, for example Redirect /path/to/file.html /path/to/other/file.html, If you want to redirect to external URL just supply it instead of relative path.

Budi Frankie Gozhali
3 years ago
Reply to  arjun

Hi arjun thank for repy, I confused to create it could you please write sample code for this case:
I need to create redirect url based on useragent for the following url:

http://mydomainold/myoldurl/

to

http://mydomainnew/mynewurl/

thanks a lot arjun you the best

arjun
3 years ago

use below one, place this in your old domain server
RewriteEngine on
RewriteRule ^(.*)$ http://new_domain_name.com/$1 [R=301,L]

4
0
Would love your thoughts, please comment.x
()
x