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 ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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 |
|
|||
|
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. |
| Thread Tools | |
| Display Modes | |
|
|