1

I want to implement the mapping issue of this tool and I cannot make it work. This is the rule:

RewriteBase /
RewriteMap mapfile txt:mapfile.txt
RewriteRule /([^?/]+)\.asp /Products.asp?Prod=${mapfile:$1}

For example, I want every file on my website which is in this format: /products.asp?prod=2

  • replaced with /LAW
  • or at least /products-LAW

I created a map file called mapfile.txt, placed it at the root web files along with the .htaccess file. I wrote only one line

law 2

and nothing happens.

What am I doing wrong?

Thanks!

splattne
  • 102,760
  • 52
  • 202
  • 249
user153230
  • 11
  • 1

2 Answers2

1

This was asked long ago, but it's still out there, so here's an answer:

Your rule has the .asp in it, so it's looking for that in the url. Since you want just the product name, try this, without the .asp in the rule.

This is for isapi_rewrite v3:

RewriteMap mapfile txt:mapfile.txt [NC]
RewriteRule /([^/]+) /Products.asp?Prod=${mapfile:$1} [NC,QSA,L]

Use [NC] on the mapfile to let you have law 2 without worrying about case. (This is in build 3.1.0.62 and newer, which was a long time ago.)

v3 handles parameters outside of the rule, so the rule doesn't need to look for the ?.

The QSA will append your Prod parameter to any incoming parameters. Since your rule was stopping at ?, I assume you want to also handle incoming parameters. So parameters will survive.

This kept your rule of stopping at a slash (after the first slash), so everything from a slash onward will be ignored for matching, and dropped from the result.

So this will rewrite urls this way:

/LAW  to  /Products.asp?Prod=2
/lAw  to  /Products.asp?Prod=2
/LAW?abc=123  to  /Products.asp?Prod=2&abc=123
/LAW/  to  /Products.asp?Prod=2
/LAW/?abc=123  to  /Products.asp?Prod=2&abc=123  (slash is dropped, but parameters survive)
/LAW/morestuff  to  /Products.asp?Prod=2   (/morestuff is dropped)
/LAW/morestuff?abc=123  to  /Products.asp?Prod=2&abc=123    (/morestuff is dropped, but the parameters survive)

Original parameters are appended to the end of the rule substitution parameter(s), determined from documentation and verified from log files.

goodeye
  • 2,389
  • 6
  • 35
  • 68
0

I believe you have the variables in your map file the wrong way round. The first var is the match, the second is the replace:

2   law
Adam Hopkinson
  • 28,281
  • 7
  • 65
  • 99