我的URL喜欢
domain.com/posts/id/title
我想更改URL
domain.com/title-xxx-id
ID和标题Querystring参数。-xxx-是静态的。
我曾经使用过
<rule name="Redirect to WWW" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^olddomain.com$" />
</conditions>
<action type="Redirect" url="https://newdomain.com/{R:0}"
redirectType="Permanent" />
</rule>
要域更改,但现在我需要在同一域中更改URL,并且有两个参数
在同一域中使用URLRewrite (2.x)
更简单。这样的东西。
<rule name="friendly" stopProcessing="true">
<match url="^post/(.+)/(.+)$" negate="false" />
<action type="Redirect" url="{R:1}-xxx-{R:2}" appendQueryString="false" />
</rule>
但实际上您需要将title-xxx-id
URL发送到处理程序进行处理。您可以这样做(假设post
是您使用的控制器)。
<rule name="friendly1" stopProcessing="true">
<match url="^(.+)-xxx-(d+)$" negate="false"/>
<action type="Rewrite" url="/post?title={R:1}&id={R:2}" appendQueryString="false"/>
</rule>
实际上,这两个规则都可以一起工作。
<rule name="friendly" stopProcessing="false">
<match url="^post/(.+)/(.+)$" negate="false" />
<action type="Redirect" url="{R:1}-xxx-{R:2}" appendQueryString="false" />
</rule>
<rule name="friendly1" stopProcessing="true">
<match url="^(.+)-xxx-(d+)$" negate="false"/>
<action type="Rewrite" url="/post?title={R:1}&id={R:2}" appendQueryString="false"/>
</rule>