views:

59

answers:

1
+2  Q: 

Rewrite url issue

Hi Folks,

I'm hoping someone can help me. For my website I have a corresponding mobile site that has the same content as my full site but display it for mobile devices. Basically I want to send all requests from the full site to the mobile site unless the url variable sms exists

So in my htaccess file for my full site I have this:

RewriteCond %{QUERY_STRING}     !sms=1         [NC]
RewriteRule ^(.*)    http://mobile.mysite.co.uk/$1 [QSA,NC]

But when I got to www.mysite.co.uk/news/index.cfm&sms I get the following ColdFusion error for the full site:

File not found: /news/index.cfm 

With debugging turned on I've noticed that the CGI variable PATH_TRANSLATED has been changed from

C:\webistes\mysite\news\index.cfm

To

C:\JRun4\bin\http:\mobile.mysite.co.uk\news\index.cfm

I'm at a loss to undestand what's going on? Any help or insight would be greatly appreciated.

Additionally I'm running a multi server install of ColdFusion 8 and using Apache configured for ColdFusion.

+4  A: 

It seems like you want to make an external redirection, but your RewriteRule currently only rewrites the URL internally. Try adding the R and L flags to your rule to see if that makes a difference:

# Stop and redirect immediately to the mobile site
RewriteCond %{QUERY_STRING}     !sms=1         [NC]
RewriteCond %{HTTP_HOST}        !^mobile
RewriteRule ^(.*)    http://mobile.mysite.co.uk/$1 [QSA,NC,R,L]

I also added in a RewriteCond to make sure that it doesn't redirect you if you're already on the mobile site, in the event that both of your sites point to the same place (you can remove it if they don't; just wanted to save you the headache in the event that they did).

Tim Stone
Thank you very much Tim. Well explained and very prompt
Gary Boyle