[us...@httpd] Problems with redirects...

2009-02-16 Thread Ken Morley
I'm trying to get our Apache web server to detect and redirect incoming
requests from BlackBerry PDAs to a version of the site designed for tiny
screens.  The URL for the PDA site is identical to the main site, but
with /pda appended.

Our httpd.conf file contains:

# Redirects to accomodate PDA's and other tiny screens...
RewriteCond %{HTTP_USER_AGENT} BlackBerry [NC]
RewriteCond %{HTTP_HOST} ^www\.saddlebrook\.com$ [NC]
RewriteRule ^/(.*) http://www.saddlebrook.com/pda [L,R]

This successfully detects BlackBerrys trying to access
www.saddlebrook.com and successfully changes the URL to
http://www.saddlebrook.com/pda; as I expected.

But when the redirected browser runs through the rules again, the regexp
^www\.saddlebrook\.com$ is also matching the new URL
http://www.saddlebrook.com/pda;.  So it redirects endlessly.

Why is regexp ^www\.saddlebrook\.com$ matching
http://www.saddlebrook.com/pda; and how can I make this work correctly?
 
Thanks for any suggestions!

Ken



-
The official User-To-User support forum of the Apache HTTP Server Project.
See URL:http://httpd.apache.org/userslist.html for more info.
To unsubscribe, e-mail: users-unsubscr...@httpd.apache.org
  from the digest: users-digest-unsubscr...@httpd.apache.org
For additional commands, e-mail: users-h...@httpd.apache.org



Re: [us...@httpd] Problems with redirects...

2009-02-16 Thread Bob Ionescu
2009/2/16 Ken Morley k...@jmtg.com:
 Our httpd.conf file contains:

# Redirects to accomodate PDA's and other tiny screens...
RewriteCond %{HTTP_USER_AGENT} BlackBerry [NC]
RewriteCond %{HTTP_HOST} ^www\.saddlebrook\.com$ [NC]
RewriteRule ^/(.*) http://www.saddlebrook.com/pda [L,R]

 This successfully detects BlackBerrys trying to access
 www.saddlebrook.com and successfully changes the URL to
 http://www.saddlebrook.com/pda; as I expected.

 But when the redirected browser runs through the rules again, the regexp
 ^www\.saddlebrook\.com$ is also matching the new URL
 http://www.saddlebrook.com/pda;.  So it redirects endlessly.

 Why is regexp ^www\.saddlebrook\.com$ matching
 http://www.saddlebrook.com/pda; and how can I make this work correctly?

Your RegEx ^/(.*) is open for every request. To catch the root
request only, change it to ^/$ instead. Your condition checks the host
header. You're redirecting to the same host (www.saddlebrook.com), why
should the host header be different? It should match against your
RegEx if the host www.saddlebrook.com was requested, of course.

Bob

-
The official User-To-User support forum of the Apache HTTP Server Project.
See URL:http://httpd.apache.org/userslist.html for more info.
To unsubscribe, e-mail: users-unsubscr...@httpd.apache.org
  from the digest: users-digest-unsubscr...@httpd.apache.org
For additional commands, e-mail: users-h...@httpd.apache.org



RE: [us...@httpd] Problems with redirects...

2009-02-16 Thread Ken Morley
Bob:

Thanks for the excellent advice. That resolved the issue.  

I was mistakenly thinking that the RewriteCond did all of the matching.
I forgot about matching within the RewriteRule itself.

Thanks again!

Ken Morley


-Original Message-
From: Bob Ionescu [mailto:bobsie...@googlemail.com] 
Sent: Monday, February 16, 2009 2:26 PM
To: users@httpd.apache.org
Subject: Re: [us...@httpd] Problems with redirects...

2009/2/16 Ken Morley k...@jmtg.com:
 Our httpd.conf file contains:

# Redirects to accomodate PDA's and other tiny screens...
RewriteCond %{HTTP_USER_AGENT} BlackBerry [NC]
RewriteCond %{HTTP_HOST} ^www\.saddlebrook\.com$ [NC]
RewriteRule ^/(.*) http://www.saddlebrook.com/pda [L,R]

 This successfully detects BlackBerrys trying to access
 www.saddlebrook.com and successfully changes the URL to
 http://www.saddlebrook.com/pda; as I expected.

 But when the redirected browser runs through the rules again, the
regexp
 ^www\.saddlebrook\.com$ is also matching the new URL
 http://www.saddlebrook.com/pda;.  So it redirects endlessly.

 Why is regexp ^www\.saddlebrook\.com$ matching
 http://www.saddlebrook.com/pda; and how can I make this work
correctly?

Your RegEx ^/(.*) is open for every request. To catch the root
request only, change it to ^/$ instead. Your condition checks the host
header. You're redirecting to the same host (www.saddlebrook.com), why
should the host header be different? It should match against your
RegEx if the host www.saddlebrook.com was requested, of course.

Bob

-
The official User-To-User support forum of the Apache HTTP Server
Project.
See URL:http://httpd.apache.org/userslist.html for more info.
To unsubscribe, e-mail: users-unsubscr...@httpd.apache.org
  from the digest: users-digest-unsubscr...@httpd.apache.org
For additional commands, e-mail: users-h...@httpd.apache.org


-
The official User-To-User support forum of the Apache HTTP Server Project.
See URL:http://httpd.apache.org/userslist.html for more info.
To unsubscribe, e-mail: users-unsubscr...@httpd.apache.org
  from the digest: users-digest-unsubscr...@httpd.apache.org
For additional commands, e-mail: users-h...@httpd.apache.org