ISAPI_Rewrite 3.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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
很久以前就有人问过这个问题,但它仍然存在,所以这里有一个答案:
您的规则中有 .asp,所以它会在 url 中寻找它。 由于您只需要产品名称,请尝试此操作,不要在规则中包含 .asp。
这是针对 isapi_rewrite v3 的:
在映射文件上使用 [NC] 让您拥有
law 2
,而不必担心大小写。 (这是很久以前的版本 3.1.0.62 及更新版本中的内容。)v3 处理规则之外的参数,因此规则不需要查找
?
。QSA 会将您的 Prod 参数附加到任何传入参数中。 由于您的规则在
?
处停止,我假设您还想处理传入参数。 因此参数将保留下来。这保留了在斜杠处停止的规则(在第一个斜杠之后),因此从斜杠开始的所有内容都将在匹配时被忽略,并从结果中删除。
因此,这将以这种方式重写 url:
原始参数附加到规则替换参数的末尾,由文档确定并从日志文件验证。
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:
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:
Original parameters are appended to the end of the rule substitution parameter(s), determined from documentation and verified from log files.
我相信您的地图文件中的变量以错误的方式存在。 第一个 var 是匹配,第二个是替换:
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: