Spaces in Map Files

ISAPI_Rewrite is Apache mod_rewrite compatible URL rewriter for Microsoft IIS
User avatar
Posts: 2
Joined: 21 Aug 2013, 21:24

Spaces in Map Files

21 Aug 2013, 21:44

Hi,

How do I handle spaces in key names in a map file? For example, I wish to do a look-up on the following:

Code: Select all
mykeyname 123
my key name 456

I'm using this code in htaccess:

Code: Select all
RewriteMap mapfile txt:MAP.htaccess [NC]
RewriteCond %{HTTP:Host} ^(.+)$
RewriteCond ${mapfile:%1$1} ^(.+)$
RewriteRule ^(/.*)$ /mypage.aspx\?id=${mapfile:%1$1} [NC,L,QSA]

Currently, anything I pass in with a space is not matched. What should I do to resolve this?

Thanks

Mark

User avatar
Posts: 1264
Joined: 07 Mar 2012, 10:16

Re: Spaces in Map Files

22 Aug 2013, 23:58

Unfortunately, a space is a special character in mapfiles. And usually spaces are considered non-secure characters from IIS point of view.
We'd suggest dealing with spaces in separate rule and use mapfiles only for URLs without spaces.

Regards
Andrew

User avatar
Posts: 92
Joined: 01 Dec 2012, 14:22

Re: Spaces in Map Files

27 Aug 2013, 07:43

HeliconAndrew wrote:Unfortunately, a space is a special character in mapfiles. And usually spaces are considered non-secure characters from IIS point of view.
We'd suggest dealing with spaces in separate rule and use mapfiles only for URLs without spaces.

Regards
Andrew


Or, better- don't put spaces in URLs! It's nasty.

User avatar
Posts: 1264
Joined: 07 Mar 2012, 10:16

Re: Spaces in Map Files

27 Aug 2013, 09:25

I recently played around and it turned out you can try to use "%20" or escape the spaces "\ ".

User avatar
Posts: 2
Joined: 21 Aug 2013, 21:24

Re: Spaces in Map Files

27 Aug 2013, 22:08

Hi, sorry for the delay in responding - I had reply notifications turned off by mistake. I've now got this working by storing key names with %20 and then looking up using the following:
Code: Select all
RewriteMap mapfile txt:MAP.htaccess [NC]
RewriteMap mapfile2 int:escape
RewriteCond %{HTTP:Host} ^(.+)$
RewriteCond ${mapfile:${mapfile2:%1$1}} ^(.+)$
RewriteRule ^(/.*)$ /mypage.aspx\?id=${mapfile:${mapfile:%1$1}} [NC,L,QSA]

I completely agree about spaces in URLs being nasty. However, this is for a CMS, so I would like to have spaces handled correctly in this part of the system, then deal with rules regarding their use elsewhere. Thanks for the help. :)

Return to ISAPI_Rewrite 3.0

Who is online

Users browsing this forum: No registered users and 6 guests