加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net – 在web.config文件中设置重定向

发布时间:2020-12-15 18:49:51 所属栏目:asp.Net 来源:网络整理
导读:我试图重定向一些不友好的urls与更具描述性的。这些URL以.aspx?cid = 3916结尾,每个类别名称页面的最后一位数字不同。我想要它改为重定向到Category / CategoryName / 3916。我试过这个在web.config文件: location path="Category.aspx?cid=3916"system.w
我试图重定向一些不友好的urls与更具描述性的。这些URL以.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>

但由于它并没有结束只是扩展,它没有工作。有没有一个简单的方法来让这个工作?我使用IIS 7.5。

解决方法

>在旧页面所在的目录中打开web.config
>然后为旧位置路径和新目标添加代码如下:
<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>

您可以根据需要添加任意数量的位置路径。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读