Forum Moderators: phranque

Message Too Old, No Replies

Conditionally rewrite path of the target url

         

Alex_T

7:31 am on Mar 4, 2004 (gmt 0)

10+ Year Member



I just finished the mobile version of my forum. So users can visit

[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

jdMorgan

8:21 am on Mar 4, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Alex_T,

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

Alex_T

9:02 am on Mar 4, 2004 (gmt 0)

10+ Year Member



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

Alex_T

10:19 am on Mar 4, 2004 (gmt 0)

10+ Year Member



I tried it this way, but it doesn't work:

#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]

jdMorgan

10:07 pm on Mar 4, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member




#
# 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

Alex_T

7:44 am on Mar 5, 2004 (gmt 0)

10+ Year Member



Thank you Jim.

Must definitely do some more research on this topic!

Alex