http - IIS 7 友好 URL 重写

标签 http iis url-rewriting seo

我见过一千个这样的例子:

<rule name="ex1" enabled="false" stopProcessing="true">
    <match url="^article/([^/]+)/?$" />
    <conditions>
        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
    </conditions>
    <action type="Rewrite" url="article/{R:1}.html" />
</rule>

我可以很容易地开始工作。然而,我想要做的是将 www.mydomain.net/test 重写为 www.mydomain.net/test.html 我试图使用下面的配置工作。

<rule name="ex2" enabled="true" stopProcessing="true">
    <match url="^/([^/]+)/?$" />
    <conditions>
        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
    </conditions>
    <action type="Rewrite" url="/{R:1}.html" />
</rule>

不幸的是,我没有取得任何成功,每次尝试都会得到一个简单的 404。虽然,当我测试我的正则表达式时,它对我希望匹配的任何东西都是成功的——例如www.mydomain.net/test.

任何人都可以深入了解这是为什么吗?

(使用 Win7、IIS7 旗舰版)。

最佳答案

你可以尝试匹配这个:

"^([^/]+)/?$"

并替换为:

{R:1}.html

我不确定,但我认为 IIS 与前导/不匹配,所以这可能是导致重写失败的原因。

示例:http://regexr.com?36jiq

关于http - IIS 7 友好 URL 重写,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19142453/

相关文章:

c# - 无法使用 GET 请求发送具有此动词类型的内容正文

html - 使用 w3m 转储 html 源代码会产生意想不到的字符/符号

iis - 在 ColdFusion 中使用 cgi.PATH_INFO 在 URL 中使用 unicode 的问题

iis - 404 错误 - Google 尝试索引 ColdFusion CFC

java - Tuckey URL 重写中的转义问号(XML/Regex)

iis-7 - 如何使用 IIS7 修复 CSS 文件内链接的 URL 重写

javascript - 如何为 XMLHTTPRequest 指定外部网站

multithreading - Delphi/Indy IdHttpServer 不是多线程的?

git - 在 Windows Server 2012 R2/IIS 上运行 Git 服务器

ssl - 重写 URL iis 7 - https ://www. somewhere.com -> https ://somewhere. com