Pea*_*rry 48 asp.net web-config http-redirect
我正在尝试将一些不友好的网址重定向到更具描述性的网址.这些网址.aspx?cid=3916以每个类别名称页面的最后数字不同而结束.我希望它改为重定向到Category/CategoryName/3916.我在web.config文件中试过这个:
<location path="Category.aspx?cid=3916">
<system.webServer>
<httpRedirect enabled="true" destination="http://www.site.com/Category/CategoryName/3916" httpResponseStatus="Permanent" />
</system.webServer>
Run Code Online (Sandbox Code Playgroud)
但由于它并没有以扩展名结尾,所以它没有用.是否有一种简单的方法可以让它发挥作用?我正在使用IIS 7.5.
MUG*_*G4N 53
然后为旧位置路径和新目标添加代码,如下所示:
<configuration>
<location path="services.htm">
<system.webServer>
<httpRedirect enabled="true" destination="http://domain.com/services" httpResponseStatus="Permanent" />
</system.webServer>
</location>
<location path="products.htm">
<system.webServer>
<httpRedirect enabled="true" destination="http://domain.com/products" httpResponseStatus="Permanent" />
</system.webServer>
</location>
</configuration>
Run Code Online (Sandbox Code Playgroud)您可以根据需要添加任意数量的位置路径.
vcs*_*nes 24
您可能希望查看URL Rewrite之类的内容,将URL重写为更加用户友好的URL,而不是使用简单的URL httpRedirect.然后你可以制定这样的规则:
<system.webServer>
<rewrite>
<rules>
<rule name="Rewrite to Category">
<match url="^Category/([_0-9a-z-]+)/([_0-9a-z-]+)" />
<action type="Rewrite" url="category.aspx?cid={R:2}" />
</rule>
</rules>
</rewrite>
</system.webServer>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
152388 次 |
| 最近记录: |