Rewriting Question Marks

This is a discussion on Rewriting Question Marks within the Apache Web Server forums, part of the Web Server and Related Forums category; hello! I am trying to rewrite (1) into (2). Following a wget of a dynamic site the actual unix filename ...


Go Back   Usenet Forums > Web Server and Related Forums > Apache Web Server

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 09-30-2004
Surabaja Johnny
 
Posts: n/a
Default Rewriting Question Marks

hello!

I am trying to rewrite (1) into (2).
Following a wget of a dynamic site the
actual unix filename is "foo.bar?id=44.html"
referenced in html pages as "foo.bar?id=44"

(1) http://localhost/xxx/foo.bar?id=44
(2) http://localhost/xxx/foo.bar%3Fid=44.html

The best I could come up with is the following:

RewriteCond %{QUERY_STRING} id\=([[:digit:]]+)
RewriteRule (.*) $1\%3Fid=%1\.html? [R]

if I point my browser to (2) the page shows up regularly
if I point my browser to (1) i get the following error

"The requested URL /xxx/foo.bar%3Fid=44.html was not found on this server."
....and the location bar changes: %3F turns into %253F

what am I missing?
TIA
SJ
  #2 (permalink)  
Old 09-30-2004
Thomas Mlynarczyk
 
Posts: n/a
Default Re: Rewriting Question Marks

Also sprach Surabaja Johnny:

> hello!
>
> I am trying to rewrite (1) into (2).
> Following a wget of a dynamic site the
> actual unix filename is "foo.bar?id=44.html"


Maybe you could choose a different filename - if it's always foo.bar then
44.html should do and you wouldn't have to bother with the question mark at
all.

> referenced in html pages as "foo.bar?id=44"
>
> (1) http://localhost/xxx/foo.bar?id=44
> (2) http://localhost/xxx/foo.bar%3Fid=44.html
>
> The best I could come up with is the following:
>
> RewriteCond %{QUERY_STRING} id\=([[:digit:]]+)
> RewriteRule (.*) $1\%3Fid=%1\.html? [R]


Have you tried
RewriteRule ^(.*)$ $1?id=%1.html?
or
RewriteRule ^(.*)$ $1\?id=%1.html?
(possibly without the [R] flag, unless you really need it)?

> if I point my browser to (2) the page shows up regularly


Because the RewriteCond fails, as there is no query string (the ? being
escaped). Thus, no rewriting will be done, but the %3F will be considered an
escaped ?, as intended.

> if I point my browser to (1) i get the following error
>
> "The requested URL /xxx/foo.bar%3Fid=44.html was not found on this
> server."


The query string is stripped off before the rewriting stuff is run, so
RewriteRule will match (.*) against xxx/foo.bar and, as it matches, will
replace it by xxx/foo.bar%3Fid=44.html. This is sent to the browser to tell
it to request this new URL....

> ...and the location bar changes: %3F turns into %253F


.... in the process, the special character % is escaped and becomes %25 (25
is the hex code of %). So then the browser requests a URL containing %3F
rather than ? and then it's no wonder it can't be found.



  #3 (permalink)  
Old 10-02-2004
Joachim Ring
 
Posts: n/a
Default Re: Rewriting Question Marks

> "The requested URL /xxx/foo.bar%3Fid=44.html was not found on this server."
> ...and the location bar changes: %3F turns into %253F


use noescape flag [NE,R] for rewriterule.

Joachim
 


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 09:51 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0