我可以制作这个web.config重写规则吗?(Can I make this web.config rewrite rule?)

在web.config中,我想为我的ASP.NET项目设置以下规则:

请求:

mydomain.com/123/some-page

返回页面

mydomain.com/collection/123-some-page.html

换一种说法

domain/x/y should fetch and return domain/collection/x-y.html

访问者仍应在浏览器网址中看到域/ x / y。

我可以制作这样的重写规则吗?

In web.config I would like to set up the following rule for my ASP.NET project:

A request to:

mydomain.com/123/some-page

returns page

mydomain.com/collection/123-some-page.html

In other words

domain/x/y should fetch and return domain/collection/x-y.html

The visitor should still see the domain/x/y in the browser url.

Can I make such a rewrite rule?

最满意答案

请记住在IIS中安装url rewrite模块,并在web.config设置下面的规则

<rewrite> <rules> <rule name="My rewrite"> <match url="^(.*)/(.*)$" /> <action type="Rewrite" url="collection/{R:1}-{R:2}.html" /> </rule> </rules> </rewrite>

Remember to install url rewrite module in IIS and set below rule in web.config

<rewrite> <rules> <rule name="My rewrite"> <match url="^(.*)/(.*)$" /> <action type="Rewrite" url="collection/{R:1}-{R:2}.html" /> </rule> </rules> </rewrite>我可以制作这个web.config重写规则吗?(Can I make this web.config rewrite rule?)

在web.config中,我想为我的ASP.NET项目设置以下规则:

请求:

mydomain.com/123/some-page

返回页面

mydomain.com/collection/123-some-page.html

换一种说法

domain/x/y should fetch and return domain/collection/x-y.html

访问者仍应在浏览器网址中看到域/ x / y。

我可以制作这样的重写规则吗?

In web.config I would like to set up the following rule for my ASP.NET project:

A request to:

mydomain.com/123/some-page

returns page

mydomain.com/collection/123-some-page.html

In other words

domain/x/y should fetch and return domain/collection/x-y.html

The visitor should still see the domain/x/y in the browser url.

Can I make such a rewrite rule?

最满意答案

请记住在IIS中安装url rewrite模块,并在web.config设置下面的规则

<rewrite> <rules> <rule name="My rewrite"> <match url="^(.*)/(.*)$" /> <action type="Rewrite" url="collection/{R:1}-{R:2}.html" /> </rule> </rules> </rewrite>

Remember to install url rewrite module in IIS and set below rule in web.config

<rewrite> <rules> <rule name="My rewrite"> <match url="^(.*)/(.*)$" /> <action type="Rewrite" url="collection/{R:1}-{R:2}.html" /> </rule> </rules> </rewrite>