在web.config文件中设置重定向 [英] Setting up redirect in web.config file

查看:2117
本文介绍了在web.config文件中设置重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图重定向与更多的人描述一些不友好的URL。这些URL以的.aspx?CID = 3916 与上次数字在每个类别名称页不同。我想它,而不是重定向到类别/类别名称/ 3916 。我在的web.config试过这个文件:

 <位置路径=?Category.aspx CID = 3916>
< system.webServer>
  < HTT predirect启用=真正的目标=htt​​p://www.site.com/Category/CategoryName/3916HTT presponseStatus =永久/>
< /system.webServer>

但因为它没有只用扩展名结尾,它没有工作。有没有一种简单的方法来得到这个工作?我使用的是IIS 7.5。


解决方案

    在目录中的那里的老页驻留
  1. 开启的web.config

  2. 然后加入code的老位置的路径和新的目标如下:

     <结构>
      <位置路径=services.htm>
        < system.webServer>
          < HTT predirect启用=真正的目标=htt​​p://domain.com/servicesHTT presponseStatus =永久/>
        < /system.webServer>
      < /地点>
      <位置路径=products.htm>
        < system.webServer>
          < HTT predirect启用=真正的目标=htt​​p://domain.com/productsHTT presponseStatus =永久/>
        < /system.webServer>
      < /地点>
    < /结构>


您可以添加多个位置路径是必要的。

I'm trying to redirect some unfriendly urls with more descriptive ones. These urls end in .aspx?cid=3916 with the last digits being different for each category name page. I want it to instead redirect to Category/CategoryName/3916. I tried this in the web.config file:

<location path="Category.aspx?cid=3916">
<system.webServer>
  <httpRedirect enabled="true" destination="http://www.site.com/Category/CategoryName/3916" httpResponseStatus="Permanent" />
</system.webServer>

but since it didn't end with just the extension, it didn't work. Is there an easy way to get this to work? I'm using IIS 7.5.

解决方案

  1. Open web.config in the directory where the old pages reside
  2. Then add code for the old location path and new destination as follows:

    <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>
    

You may add as many location paths as necessary.

这篇关于在web.config文件中设置重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆