zoukankan      html  css  js  c++  java
  • ASP.NET web application中的redirect

    在开发ASP.NET MVC web application过程中,开发上线了新系统后,需要把老系统的url redirect新系统下

    其中在项目系统目录下有一个文件 301RedirectsPages.config, 内容如下:

    <rewriteMaps>
        <rewriteMap name="Redirects">
               <add key="/contact-us.aspx" value="/contact-us" />
            <add key="/services-solutions" value="/services-and-solutions" />
            <add key="/sales-support" value="/sales-and-support" />
            <add key="/events-news" value="/events-and-news" />
            <add key="/services-solutions/services.aspx" value="/services-and-solutions/services" />
            <add key="/services-solutions/solutions.aspx" value="/services-and-solutions/solutions" />
            </rewriteMap>
    </rewriteMaps>



    在web.config文件中,在system.webServer下面,有一个rewrite节点,显示如下:
    <system.webServer>
        <rewrite  xdt:Transform="Replace">
          <rewriteMaps configSource="301RedirectsPages.config" />
          <rules>
            <rule name="Redirect to HTTPS" stopProcessing="true">
              <match url="(.*)" />
              <conditions>
                <add input="{HTTPS}" pattern="^OFF$" />
              </conditions>
              <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" />
            </rule>
            <rule name="Remove trailing slash" stopProcessing="true">
              <match url="(.*)/$" />
              <conditions>
                <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
              </conditions>
              <action type="Redirect" redirectType="Permanent" url="{R:1}" />
            </rule>
            <rule name="Redirects">
              <match url=".*" />
              <conditions>
                <add input="{Redirects:{REQUEST_URI}}" pattern="(.+)" />
              </conditions>
              <action type="Redirect" url="{C:1}" appendQueryString="true" />
            </rule>
          </rules>
        </rewrite>
    </system.webServer>
    
    

    这种情况下,在浏览器窗口输入URL:

    localhost/contact-us.aspx 将自动redirect到 localhost/contact-us

    localhost/services-solutions/services.aspx 自动redirect到 localhost/services-and-solutions/services

    localhost/services-solutions/solutions.aspx 自动redirect到 localhost/services-and-solutions/solutions

    但是,当你输入

    localhost/services-solutions 不能自动redirect到 localhost/services-and-solutions

    localhost/sales-support 不能自动redirect到 localhost/sales-and-support

    localhost/events-news 不能自动redirect到 localhost/events-and-news

    查找了半天的原因,才发现是在web.config 中的设置

    appendQueryString="true" 应该改成 appendQueryString="false"

    也就是这一行  <action type="Redirect" url="{C:1}" appendQueryString="true" />

    应该改成 <action type="Redirect" url="{C:1}" appendQueryString="false" />

    改成后的web.config文件如下:

     <rewrite  xdt:Transform="Replace">
          <rewriteMaps configSource="301RedirectsPages.config" />
          <rules>
            <rule name="Redirect to HTTPS" stopProcessing="true">
              <match url="(.*)" />
              <conditions>
                <add input="{HTTPS}" pattern="^OFF$" />
              </conditions>
              <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" />
            </rule>
            <rule name="Remove trailing slash" stopProcessing="true">
              <match url="(.*)/$" />
              <conditions>
                <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
              </conditions>
              <action type="Redirect" redirectType="Permanent" url="{R:1}" />
            </rule>
            <rule name="Redirects">
              <match url=".*" />
              <conditions>
                <add input="{Redirects:{REQUEST_URI}}" pattern="(.+)" />
              </conditions>
              <action type="Redirect" url="{C:1}" appendQueryString="false" />
            </rule>
          </rules>
        </rewrite>


  • 相关阅读:
    IOS开发关于测试的好的网址资源
    创建型模式--工厂模式
    在XcodeGhost事件之后,获取更纯净的Xcode的方法。
    算法积累:解决如何获取指定文件夹路径或者文件路径下所有子文件后缀为.h .m .c的文本的行数
    结构型模式--装饰模式
    设计模式 总揽 通过这篇随笔可以访问所需要了解的设计模式
    IOS之未解问题--关于IOS图像渲染CPU和GPU
    链接
    Matlab2014下载和破解方法,以及Matlab很好的学习网站
    苹果Mac隐藏壁纸在哪里?Mac隐藏壁纸查找教程
  • 原文地址:https://www.cnblogs.com/wphl-27/p/6806485.html
Copyright © 2011-2022 走看看