You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Andrew Dixon <an...@andrewdixon.co.uk> on 2007/07/18 10:06:00 UTC

[users@httpd] RewriteMap issue - Escaping a space

Hi.

We have a RewriteMap configured and working fine, however we need to add a
URL to the map that contains a space. I have tried several different things,
but none of them work. What I have in the map file is:

sub_page.asp/title/Paris Outbound/section/General/editID/337 paris/outbound

I have tried replacing the space with %20 and . (dot) and adding a \ before
the space but none of them worked.

How do you escape a in the map file?

Thanks in advance for any help.

-- 
Kind regards,

Andrew

Re: [users@httpd] RewriteMap issue - Escaping a space

Posted by Andrew Dixon <an...@andrewdixon.co.uk>.
Hi Joshua.

Worked like a dream. Thanks.

Andrew.

On 19/07/07, Joshua Slive <jo...@slive.ca> wrote:
>
> On 7/19/07, Andrew Dixon <an...@andrewdixon.co.uk> wrote:
>
> > I tried using the THE_REQUEST, but that get a space in it as well as it
> > gives:
> >
> > GET /sub_page.cfm/title/Paris
> > Outbound/section/General/editID/337
> >
> > And there is space between the GET and the URI. I also tried several of
> the
> > other variables, REQUEST_URI and REQUEST_FILENAME, but they either
> contain
> > the space or not the whole string. The rewrite rules are:
> >
> > RewriteMap theMap txt:/tmp/theMap.txt
> >  RewriteCond ${theMap:$1¦NotFound} !NotFound
> > RewriteRule ^/(.*) ${theMap:$1} [R=301,L]
>
> My other idea was something like the following:
>
> RewriteRule "(.*) (.*)" $1SPACE$2
> RewriteCond ${theMap:$1¦NotFound} !NotFound
> RewriteRule ^/(.*) ${theMap:$1} [R=301]
>
> And, of course, in your map file you would need to replace any space
> with the string SPACE. (Again, you'll need to check the rewriteLog to
> see how to actually do that first match. It is possible that you need
> to match against %20 rather than a raw space. I've never tried it.)
> And another caveat: this will only work for one space in the URL. You
> could add more RewriteRules to get more spaces, and could probably
> handle an arbitrary number with some added complication.
>
> Joshua.
>
> ---------------------------------------------------------------------
> 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-unsubscribe@httpd.apache.org
>    "   from the digest: users-digest-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org
>

Re: [users@httpd] RewriteMap issue - Escaping a space

Posted by Joshua Slive <jo...@slive.ca>.
On 7/19/07, Andrew Dixon <an...@andrewdixon.co.uk> wrote:

> I tried using the THE_REQUEST, but that get a space in it as well as it
> gives:
>
> GET /sub_page.cfm/title/Paris
> Outbound/section/General/editID/337
>
> And there is space between the GET and the URI. I also tried several of the
> other variables, REQUEST_URI and REQUEST_FILENAME, but they either contain
> the space or not the whole string. The rewrite rules are:
>
> RewriteMap theMap txt:/tmp/theMap.txt
>  RewriteCond ${theMap:$1¦NotFound} !NotFound
> RewriteRule ^/(.*) ${theMap:$1} [R=301,L]

My other idea was something like the following:

RewriteRule "(.*) (.*)" $1SPACE$2
RewriteCond ${theMap:$1¦NotFound} !NotFound
RewriteRule ^/(.*) ${theMap:$1} [R=301]

And, of course, in your map file you would need to replace any space
with the string SPACE. (Again, you'll need to check the rewriteLog to
see how to actually do that first match. It is possible that you need
to match against %20 rather than a raw space. I've never tried it.)
And another caveat: this will only work for one space in the URL. You
could add more RewriteRules to get more spaces, and could probably
handle an arbitrary number with some added complication.

Joshua.

---------------------------------------------------------------------
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-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] RewriteMap issue - Escaping a space

Posted by Andrew Dixon <an...@andrewdixon.co.uk>.
On 18/07/07, Joshua Slive <jo...@slive.ca> wrote:
>
> On 7/18/07, Andrew Dixon <an...@andrewdixon.co.uk> wrote:
>
> > Here is what I got from the RewriteLog set on level 9 (highest). I
> assume
> > the line we are looking for is:
> >
> > map lookup FAILED: map=citybreaksMap[txt] key=sub_page.cfm/title/Paris
> > Outbound/section/General/editID/337
> >
> > There is it with the space. Now, like you say you can't use the space as
> it
> > is the field delimiter, any suggestions?
>
> Interesting. It would perhaps be helpful to show the actual
> RewriteRules so that we could see where that key is coming from. I
> have a couple suggestions:
>
> 1. Use a different key where the space is properly encoded. For
> example, THE_REQUEST is a variable that often contains a more "raw"
> version of the requested path (probably including %20 in place of the
> space here).
>
> 2. Have mod_rewrite replace the space with something else before
> looking in the map.
>
> Joshua.
>
> ---------------------------------------------------------------------
> 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-unsubscribe@httpd.apache.org
>    "   from the digest: users-digest-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org
>
>
Hi Joshua.

I tried using the THE_REQUEST, but that get a space in it as well as it
gives:

GET /sub_page.cfm/title/Paris Outbound/section/General/editID/337

And there is space between the GET and the URI. I also tried several of the
other variables, REQUEST_URI and REQUEST_FILENAME, but they either contain
the space or not the whole string. The rewrite rules are:

RewriteMap theMap txt:/tmp/theMap.txt
RewriteCond ${theMap:$1¦NotFound} !NotFound
RewriteRule ^/(.*) ${theMap:$1} [R=301,L]


Any other ideas?
-- 
Kind regards,

Andrew

Re: [users@httpd] RewriteMap issue - Escaping a space

Posted by Joshua Slive <jo...@slive.ca>.
On 7/18/07, Andrew Dixon <an...@andrewdixon.co.uk> wrote:

> Here is what I got from the RewriteLog set on level 9 (highest). I assume
> the line we are looking for is:
>
> map lookup FAILED: map=citybreaksMap[txt] key=sub_page.cfm/title/Paris
> Outbound/section/General/editID/337
>
> There is it with the space. Now, like you say you can't use the space as it
> is the field delimiter, any suggestions?

Interesting. It would perhaps be helpful to show the actual
RewriteRules so that we could see where that key is coming from. I
have a couple suggestions:

1. Use a different key where the space is properly encoded. For
example, THE_REQUEST is a variable that often contains a more "raw"
version of the requested path (probably including %20 in place of the
space here).

2. Have mod_rewrite replace the space with something else before
looking in the map.

Joshua.

---------------------------------------------------------------------
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-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] RewriteMap issue - Escaping a space

Posted by Andrew Dixon <an...@andrewdixon.co.uk>.
On 18/07/07, Joshua Slive <jo...@slive.ca> wrote:
>
> On 7/18/07, Andrew Dixon <an...@andrewdixon.co.uk> wrote:
> > Hi.
> >
> > We have a RewriteMap configured and working fine, however we need to add
> a
> > URL to the map that contains a space. I have tried several different
> things,
> > but none of them work. What I have in the map file is:
> >
> >  sub_page.asp/title/Paris
> > Outbound/section/General/editID/337 paris/outbound
> >
> > I have tried replacing the space with %20 and . (dot) and adding a \
> before
> > the space but none of them worked.
> >
> > How do you escape a in the map file?
>
> I've never tried this myself, but I imagine what you need to do is
> match the encoding used on whatever the RewriteMap is called with. Use
> the RewriteLog to see what the encoding on the matched string is and
> duplicate that.
>
> You certainly can't use a bare space since space is the field delimiter.
>
> Joshua.
>
> ---------------------------------------------------------------------
> 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-unsubscribe@httpd.apache.org
>    "   from the digest: users-digest-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org
>
>
Hi Joshua.

Here is what I got from the RewriteLog set on level 9 (highest). I assume
the line we are looking for is:

map lookup FAILED: map=citybreaksMap[txt] key=sub_page.cfm/title/Paris
Outbound/section/General/editID/337

There is it with the space. Now, like you say you can't use the space as it
is the field delimiter, any suggestions?

Kind regards,

Andrew

Re: [users@httpd] RewriteMap issue - Escaping a space

Posted by Joshua Slive <jo...@slive.ca>.
On 7/18/07, Andrew Dixon <an...@andrewdixon.co.uk> wrote:
> Hi.
>
> We have a RewriteMap configured and working fine, however we need to add a
> URL to the map that contains a space. I have tried several different things,
> but none of them work. What I have in the map file is:
>
>  sub_page.asp/title/Paris
> Outbound/section/General/editID/337 paris/outbound
>
> I have tried replacing the space with %20 and . (dot) and adding a \ before
> the space but none of them worked.
>
> How do you escape a in the map file?

I've never tried this myself, but I imagine what you need to do is
match the encoding used on whatever the RewriteMap is called with. Use
the RewriteLog to see what the encoding on the matched string is and
duplicate that.

You certainly can't use a bare space since space is the field delimiter.

Joshua.

---------------------------------------------------------------------
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-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org