[Last Call] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1558
  • Last Modified:

isapi rewrite and map file not working

I don't seem to be able to get this question answered, but I'll try again.
I am playing around with isapi rewrite lite with only limited success. I'm trying to substitute the url querystring parameter with it's value. I have gotten it work, but I can't seem to be able to implement a parameter substitution using a map file. I'm working in classic ASP on Windows 2003 with isapi version 3.

In my httpd.conf file this works:

RewriteCond %{QUERY_STRING} ^cy=(\d+)$ [NC]
RewriteRule ^imagine/ketubot/$ imagine/ketubot/%1? [NC,R=301,L]
RewriteRule ^imagine/ketubot/(\d+)$ imagine/ketubot/?cy=$1 [NC,L]

and I get a url like /imagine/ketubot/5 in place of /imagine/ketubot/?cy=5

This doesn't work:

RewriteMap mapfile txt:mapcountries.txt [NC]
RewriteRule ^imagine/ketubot/(\d+)$ imagine/ketubot/?cy=${mapfile:$1}

and it remains with /imagine/ketubot/?cy=5
instead of what I hoped to get: /imagine/ketubot/Algeria

I would appreciate any help with this. Thanks
  • 5
  • 3
2 Solutions
I am not good at rewrites, but what i can gather:

1. Try using absolute path in your RewriteMap (after the colon).
2. Remove [NC]. I read that a look-up into a map file cannot be case insensitive.
3. Add a second argument to define the default action in event a country code isnt matched. This is the pipe char plus a URL.
4. Add a redirect flag and last flag to your target url.

I believe the R is appropriate to indicate the rewrite rule is a redirect. Of course, L flag says stop here.

RewriteMap mapfile txt:C:/Absolute/Path/To/mapcountries.txt
RewriteRule ^imagine/ketubot/(\d+)$ imagine/ketubot/?cy=${mapfile:$1|/not-found.html} [R,L]

Open in new window

Also, note on APache website: "The RewriteMap directive may not be used in <Directory> sections or .htaccess files. You must declare the map in server or virtualhost context. You may use the map, once created, in your RewriteRule and RewriteCond directives in those scopes. You just can't declare it in those scopes. "

So be sure the RewriteMap directive goes in the Apache Configuration file. RewriteMap cannot go in .htaccess. I see it looks like you have it in httpd.conf.

See: http://httpd.apache.org/docs/trunk/rewrite/rewritemap.html

I hope this helps you. Gregg
I had one more thought. If you have your RewriteRules in the Apache Configuration file, dont you need a leading slash in both pattern and target?

RewriteRule ^/imagine/ketubot/(\d+)$ /imagine/ketubot/?cy=${mapfile:$1}

-- I just cant remember.
avirAuthor Commented:
Thanks for your input. Not having an absolute path to the map file was part of the problem. I found the rest of the solution at:
I added "default.asp" to my rules and that seemed to have been missing previously. I also was confused between rewriting and redirecting and I guess I wanted both.
The examples given use the [NC] flag so I left that in. I don't need the leading slash because I have   RewriteBase /   at the top of the file.
Here is the code that works:

RewriteMap mapfile1 txt:C:/Program Files/Helicon/ISAPI_Rewrite3/mapcountries1.txt
RewriteMap mapfile2 txt:C:/Program Files/Helicon/ISAPI_Rewrite3/mapcountries2.txt
RewriteCond %{QUERY_STRING} ^cy=(\d+) [NC]
RewriteRule ^imagine/ketubot/default\.asp$ imagine/ketubot/${mapfile1:%1}.htm? [NC,R,]
RewriteRule ^imagine/ketubot/([^./]+).htm$ imagine/ketubot/default.asp?cy=${mapfile2:$1} [NC,L]
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

good to see you have a solution. best of luck!
avir, for fun, experiment with the [NC] on the mapfile values. See if nocase does not matter.
avirAuthor Commented:
Doesn't seem to make a difference one way or another. I removed the [NC] and changed the values to with and without uppercase and it doesn't seem to matter. It still works. Unless I'm not understanding what [NC] means.
Thanks, i was interested in the results. :)
avirAuthor Commented:
I searched and found a comprehensive solution to my problem on the Helicon forum.

Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now