如何使用 web.config 重写 IIS Url 重写模块中网页的 url?
How to rewrite the url of a webpage in IIS UrlRewriteModule with web.config?
我搜索消除 html 文件扩展名的规则(或一组规则)
但同时能够像下面的示例一样重写浏览器 url:
category1_pageid2.html 到 categories_page(对 SEO 更友好)
我有一个带有 IIS 8.5 的共享主机环境 IIS_UrlRewriteModule 7.1.1952.0
非常感谢您的帮助
在 IIS 中,我创建了一条新规则:
然后在下一个对话框中,我添加了 Pattern categories_page 以及 {QUERY_STRING}
匹配模式的条件c=(\d+)&p=(\d+)
(尽管您可能不需要查询字符串 - 根据您的需要自定义)。对于 Action,我添加了 Rewrite URL of category{C:1}_pageid{C:2}.html
。如果不需要查询字符串,则可以取消选中 append query string.
的复选框
查看站点的 web.config 文件,我看到下面的 XML:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="category-page">
<match url="categories_page" />
<action type="Rewrite" url="category{C:1}_pageid{C:2}.html" />
<conditions>
<add input="{QUERY_STRING}" pattern="c=(\d+)&p=(\d+)" />
</conditions>
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
在我的浏览器中尝试此操作时,当我导航至 localhost/categories_page?c=1&p=2
:
时,我看到了 category1_pageid2.html 页面
其他选项包括 rewrite map - see this answer 的简短说明。
我搜索消除 html 文件扩展名的规则(或一组规则) 但同时能够像下面的示例一样重写浏览器 url:
category1_pageid2.html 到 categories_page(对 SEO 更友好)
我有一个带有 IIS 8.5 的共享主机环境 IIS_UrlRewriteModule 7.1.1952.0
非常感谢您的帮助
在 IIS 中,我创建了一条新规则:
然后在下一个对话框中,我添加了 Pattern categories_page 以及 {QUERY_STRING}
匹配模式的条件c=(\d+)&p=(\d+)
(尽管您可能不需要查询字符串 - 根据您的需要自定义)。对于 Action,我添加了 Rewrite URL of category{C:1}_pageid{C:2}.html
。如果不需要查询字符串,则可以取消选中 append query string.
查看站点的 web.config 文件,我看到下面的 XML:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="category-page">
<match url="categories_page" />
<action type="Rewrite" url="category{C:1}_pageid{C:2}.html" />
<conditions>
<add input="{QUERY_STRING}" pattern="c=(\d+)&p=(\d+)" />
</conditions>
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
在我的浏览器中尝试此操作时,当我导航至 localhost/categories_page?c=1&p=2
:
其他选项包括 rewrite map - see this answer 的简短说明。