Forum Moderators: phranque
[mysite.com...]
to have see have the same content as in
[mysite.com...]
...only handheld-friendly.
Now to the question:
In my forum there are a lot of hard-links to other parts of the forum. So it can happen that a user visiting the /mobile/ part clicks on one of those links, which directs him to the non-mobile /forums/ part. Is there a way, like with referrer check, to automatically rewrite /forums/ to /mobile/ in those cases using .htaccess?
Hope I didn't sound too complicated!
Thank you,
Alex
Welcome to WebmasterWorld [webmasterworld.com]!
Referrers are not reliable enough for this kind of application. They are often blocked by intervening caches and proxies. You might look into checking the HTTP_USER_AGENT of your mobile users. That might be more reliable than using HTTP_REFERER.
mod_rewrite can easily do the job, but you'll need a reliable way to detect modile users; Doing the "rewrite" is easy, but finding the right "conditional" is hard.
Alternatively, you might consider using relative URLs in your forum links. Then there would be no need for any rewrites at all.
Jim
thank you for your fast reply. The forum software I am using is vBulletin 3.0 (RC4), and it automatically parses relative urls to absolute urls for new posts. Perhaps I could hack the necessary php code, but that wouldn't solve the problem for the existing parsed urls (unless I also change them in my database directly).
Would you mind helping me with the .htaccess definition to check for the user agent (let's say we check for two user agents, 'Avantgo' and 'iSiloX') and apply the rewrite accordingly?
Thanks again!
Alex
#browser redirects For PDA Based Browsers
RewriteCond %{HTTP_USER_AGENT} "Windows CE" [NC,OR] #Windows CE and Pocket PC
RewriteCond %{HTTP_USER_AGENT} "Blazer" [NC,OR] #Handspring Blazer Browser
RewriteCond %{HTTP_USER_AGENT} "Elaine" [NC,OR] #RIM Devices
RewriteCond %{HTTP_USER_AGENT} "^WAP.*$" [NC,OR] #WAP Browsers
RewriteCond %{HTTP_USER_AGENT} "AvantGo" [NC,OR] #AvantGo Service
RewriteCond %{HTTP_USER_AGENT} "^Lynx/.*" [NC] #Lynx Text Browser
RewriteRule ^(.*)/forums/(.*)$ ^(.*)/mobile/(.*)$ [R,L]
#
# Once before any mod_rewrite code
Options +FollowSymLinks
RewriteEngine on
#
#Browser redirects For PDA-based browsers
#
# Windows CE and Pocket PC
RewriteCond %{HTTP_USER_AGENT} Windows\ CE [NC,OR]
# Handspring Blazer Browser
RewriteCond %{HTTP_USER_AGENT} Blazer [NC,OR]
# RIM Devices
RewriteCond %{HTTP_USER_AGENT} Elaine [NC,OR]
# WAP Browsers
RewriteCond %{HTTP_USER_AGENT} ^WAP [NC,OR]
# AvantGo Service
RewriteCond %{HTTP_USER_AGENT} AvantGo [NC,OR]
#Lynx Text Browser
RewriteCond %{HTTP_USER_AGENT} ^Lynx/ [NC]
RewriteRule ^([^/]*)/forums/(.*) /$1/mobile/$2 [R=301,L]
Ref: Introduction to mod_rewrite [webmasterworld.com]
Jim