Forum Moderators: open
# Default Template
SetEnvIf Remote_Addr . my_template_file=default
# Change template based on visitor's browser
SetEnvIf User-Agent \biPad\b my_template_file=iPad
SetEnvIf X-WAP-Profile \bNN70\b my_template_file=small-screen
# Allow visitor to override template selection via cookie
SetEnvIf Cookie \bmy_template_file=([^;]+); my_template_file=$1
# Redirect user-agent to selected template
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* /cgi-bin/%{ENV:my_template_file}.pl [L] # Redirect mobile devices to mobile url
# Add as many attributes/values as you like...
SetEnvIf User-Agent \b[Mm]obile\b mobile
SetEnvIf X-WAP-Profile . mobile
RewriteCond %{ENV:mobile} ^1$
RewriteCond %{REQUEST_URI} !^/mobile/
RewriteRule (.*) http://www.example.com/mobile/$1 [R=301,L]
RewriteCond %{ENV:mobile} !^1$
RewriteRule ^mobile/(.*) http://www.example.com/$1 [R=301,L] RewriteCond %{HTTP_USER_AGENT} {here you list the likely UAs, such as iPod/iPhone}
RewriteCond %{REQUEST_URI} !^/mobile
RewriteRule (.*) http://www.example.com/mobile/$1 [R=301,L]
RewriteCond %{HTTP_USER_AGENT} !{same list as before, but this time negative}
RewriteRule ^mobile/(.*) http://www.example.com/$1 [R=301,L]