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
avirAsked:
Who is Participating?
 
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:
http://www.helicontech.com/forum/10825-ISAPI_MAPFILE_Help.html
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]
0
 
GreggCommented:
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
0
 
GreggCommented:
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.
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
GreggCommented:
good to see you have a solution. best of luck!
0
 
GreggCommented:
avir, for fun, experiment with the [NC] on the mapfile values. See if nocase does not matter.
0
 
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.
0
 
GreggCommented:
Thanks, i was interested in the results. :)
0
 
avirAuthor Commented:
I searched and found a comprehensive solution to my problem on the Helicon forum.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.