ISAPI_Rewrite 3.0 版映射

发布于 2024-07-30 21:00:40 字数 486 浏览 10 评论 0原文

我想实现这个工具的映射问题,但无法使其工作。 这是规则:

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

例如,我希望网站上采用以下格式的每个文件: /products.asp?prod=2

  • 替换为 /LAW
  • 或至少/products-LAW

我创建了一个名为 mapfile.txt 的地图文件,将其与 .htaccess 文件一起放置在根 Web 文件中。 我只写了一行

law 2

,什么也没发生。

我究竟做错了什么?

谢谢!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

世态炎凉 2024-08-06 21:00:41

很久以前就有人问过这个问题,但它仍然存在,所以这里有一个答案:

您的规则中有 .asp,所以它会在 url 中寻找它。 由于您只需要产品名称,请尝试此操作,不要在规则中包含 .asp。

这是针对 isapi_rewrite v3 的:

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

在映射文件上使用 [NC] 让您拥有law 2,而不必担心大小写。 (这是很久以前的版本 3.1.0.62 及更新版本中的内容。)

v3 处理规则之外的参数,因此规则不需要查找 ?

QSA 会将您的 Prod 参数附加到任何传入参数中。 由于您的规则在 ? 处停止,我假设您还想处理传入参数。 因此参数将保留下来。

这保留了在斜杠处停止的规则(在第一个斜杠之后),因此从斜杠开始的所有内容都将在匹配时被忽略,并从结果中删除。

因此,这将以这种方式重写 url:

/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)

原始参数附加到规则替换参数的末尾,由文档确定并从日志文件验证。

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.

清风不识月 2024-08-06 21:00:41

我相信您的地图文件中的变量以错误的方式存在。 第一个 var 是匹配,第二个是替换:

2   law

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文