Iis 7 IIS 7-URL重写-我是否在正则表达式中包含http或https协议?

Iis 7 IIS 7-URL重写-我是否在正则表达式中包含http或https协议?,iis-7,url-rewriting,iis-7.5,Iis 7,Url Rewriting,Iis 7.5,在IIS 7.5(Win2k8 R2)中,我试图为这些请求创建一个新规则: http://www.domain.com/userprofile https://www.domain.com/userprofile http://domain.com/userprofile https://domain.com/userprofile 改写为: http://www.domain.com/users/?username=userprofile (or whatever the protocol/

在IIS 7.5(Win2k8 R2)中,我试图为这些请求创建一个新规则:

http://www.domain.com/userprofile
https://www.domain.com/userprofile
http://domain.com/userprofile
https://domain.com/userprofile
改写为:

http://www.domain.com/users/?username=userprofile
(or whatever the protocol/domain is)
我写的正则表达式是:

^(http|https)://(www\.domain.com|domain\.com)/([a-zA-Z0-9-]{6,35})
重写是:

{R:1}://{R:2}/users/?username={R:3}
但这是行不通的。是因为我不需要遵守协议吗?我还添加了请求不是文件或目录的条件


另外,每次更改规则时是否需要重新启动IIS?

当您要重写这些请求时,不必查看协议或域名。这在您的情况下并不重要,因为您只想重写路径

以下规则应该有效:

<rule name="Rewrite user profiles">
    <match url="([a-zA-Z0-9-]{6,35})" />
    <action type="Rewrite" url="/users/?username={R:1}" />
</rule>


更改规则时不必重新启动IIS。当web.config被修改时,IIS将自动重新启动应用程序池,从而重新加载规则。

@Marco几乎是对的,但以下是最终的工作方式:(我在IIS管理器中使用了URL重写表单)

正则表达式:

^([a-zA-Z0-9-]{6,35})(/?)$
条件:

Not a file
Not a directory

这将强制匹配直接在域之后开始,并且必须是第一个目录,或者没有尾随“/”。根据正则表达式,匹配必须在6到35个字符之间,字母数字加“-”

我认为这是一个太宽泛的规则。整个网站都崩溃了,我想这是因为它正在重写javascript文件的请求,等等。我想我需要考虑路径。这取决于你如何命名你的javascript文件。但当然,最好添加一个条件,即它不应与现有文件或目录匹配。我更关注的是,你不应该包括域名和协议。是的,你的回答肯定让我觉得。。。非常感谢。您的正则表达式模式匹配了如下内容:并重写了它们。啊,嗯,它当然会匹配
javascript
(但不是
.js
部分)。您的固定正则表达式几乎不错,但是
(/|$)
不是匹配可选尾部反斜杠的正确方法。更好地使用
^([a-zA-Z0-9-]{6,35})(/?)$