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

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.

By Arjun

I am Arjun from Hyderabad (India). I have been working as a software engineer from the last 7+ years, and it is my passion to learn new things and implement them as a practice. Aside from work, I like gardening and spending time with pets.

0 0 vote
Article Rating
Notify of
Newest Most Voted
Inline Feedbacks
View all comments
Budi Frankie Gozhali
2 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

2 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
2 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:




thanks a lot arjun you the best

2 years ago

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