简体   繁体   English

IIS重写不适用于简单重定向

[英]IIS rewrite not working for simple redirects

All I want to do is 301 redirect from old URLs to new URLs: 我要做的就是从旧网址到新网址的301重定向:

from /xx/yy/somefile.html to /xx/yy/somefile.aspx /xx/yy/somefile.html/xx/yy/somefile.aspx

some examples below: 以下是一些示例:

add key="/products/DSD-72B-SP-summary.html" value="/products/DSD-72B-SP-summary.aspx" 
add key="/products/DSD-72B-SP-detail" value="/products/DSD-72B-SP-detail.aspx" 
add key="index.html" value="default.aspx" 
add key="/product-selector.html" value="/products.aspx" 

That is all but it doesn't seem to want to work in IIS 7.5 with URL rewrite 2.0. 仅此而已,但似乎不想在URL重写2.0的IIS 7.5中工作。

I have tried at least 10-20 different rules, and rewrite map formats without any luck. 我尝试了至少10-20种不同的规则,并且重写了地图格式,但没有任何运气。 In fact I have done this so many times I have had to wipe the rules and maps from IIS and totally recopy a web.config file from a backup to unscrew what I screwed with to try and make it work. 实际上,我已经做了很多次,不得不从IIS擦除规则和映射,并从备份中完全重新复制web.config文件,以拧松我尝试使用的螺丝钉并使其正常工作。

All I need is a simple rule that tells IIS that if it gets a request for a *.html file to display the *.aspx file that replaced the html file. 我所需要的只是一个简单的规则,该规则告诉IIS,如果它收到了* .html文件的请求以显示替换了html文件的* .aspx文件。

    <?xml version="1.0" encoding="UTF-8"?>

<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->

<configuration>
  <appSettings configProtectionProvider="DataProtectionConfigurationProvider">
    <EncryptedData>
      <CipherData>

      </CipherData>
    </EncryptedData>
  </appSettings>
  <connectionStrings configProtectionProvider="DataProtectionConfigurationProvider">
    <EncryptedData>
      <CipherData>

      </CipherData>
    </EncryptedData>
  </connectionStrings>

  <system.web>

    <customErrors mode="On" defaultRedirect="404-NotFound.aspx">
      <error statusCode="404" redirect="404-NotFound.aspx" />
      <!--<error statusCode="403" redirect=""/>-->
    </customErrors>

    <compilation debug="true" strict="false" explicit="true" targetFramework="4.0">
            <!--<codeSubDirectories>
                <add directoryName="CSharp"/>
                <add directoryName="VB"/>
            </codeSubDirectories>-->
        </compilation>
    <authentication mode="Forms">

    </authentication>

    <membership>
      <providers>
        <clear />

      </providers>
    </membership>

    <profile>
      <providers>
        <clear />

      </providers>
    </profile>

    <roleManager enabled="false">
      <providers>
        <clear />

      </providers>
    </roleManager>

  </system.web>

  <system.webServer>
     <modules runAllManagedModulesForAllRequests="true">

        </modules>

        <defaultDocument>
            <files>

            </files>
        </defaultDocument>


    <httpErrors errorMode="Custom" defaultResponseMode="ExecuteURL">
      <remove statusCode="404" subStatusCode="-1" />
      <error statusCode="404" path="/404-NotFound.aspx" responseMode="ExecuteURL" />
    </httpErrors>
        <tracing>
            <traceFailedRequests>
                <add path="*">
                    <traceAreas>
                        <add provider="WWW Server" areas="Rewrite" verbosity="Verbose" />
                    </traceAreas>
                    <failureDefinitions statusCodes="200-500" />
                </add>
            </traceFailedRequests>
        </tracing>

  </system.webServer>
</configuration>

Make sure you clear your cache too. 确保您也清除了缓存。 Sometimes you can update a server rule but your browser will continue to show the old page. 有时您可以更新服务器规则,但浏览器将继续显示旧页面。

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
        <rules> 
            <rule name="Vanity URL" enabled="true">
                 <match url=".*" />
                 <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                     <add input="{MAPNAME:{PATH_INFO}}" pattern="(.+)" />
                 </conditions>
                 <action type="Redirect" url="{C:1}" appendQueryString="false" />
            </rule>
        </rules>
        <rewriteMaps>
            <rewriteMap name="MAPNAME">
                <add key="/products/DSD-72B-SP-summary.html" value="/products/DSD-72B-SP-summary.aspx" />
        </rewriteMap>
    </rewrite>
</system.webServer>
</configuration>

The above code it taking directly from my website with minor name changes for generality and added in your page. 上面的代码直接从我的网站取而来,并使用了较小的名称,以更改一般性并添加到您的页面中。 Try to remove other rules and isolate the issue. 尝试删除其他规则并找出问题所在。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM