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.
1 2 3 4 5 6 7 8 |
RewriteCond %{HTTP_USER_AGENT} ^.*iPhone.*$ RewriteRule ^(.*)$ http://iphone.yourdomain.com [R=301] RewriteCond %{HTTP_USER_AGENT} ^.*iPad.*$ RewriteRule ^(.*)$ http://ipad.yourdomain.com [R=301] RewriteCond %{HTTP_USER_AGENT} ^.*iPod.*$ RewriteRule ^(.*)$ http://ipod.yourdomain.com [R=301] |
For all the other user agent requests, default rewrite rules will be applied.
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
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.
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
use below one, place this in your old domain server
RewriteEngine on
RewriteRule ^(.*)$ http://new_domain_name.com/$1 [R=301,L]