[英]IIS rewrite not working for simple redirects
我要做的就是从旧网址到新网址的301重定向:
从/xx/yy/somefile.html
到/xx/yy/somefile.aspx
以下是一些示例:
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"
仅此而已,但似乎不想在URL重写2.0的IIS 7.5中工作。
我尝试了至少10-20种不同的规则,并且重写了地图格式,但没有任何运气。 实际上,我已经做了很多次,不得不从IIS擦除规则和映射,并从备份中完全重新复制web.config文件,以拧松我尝试使用的螺丝钉并使其正常工作。
我所需要的只是一个简单的规则,该规则告诉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>
确保您也清除了缓存。 有时您可以更新服务器规则,但浏览器将继续显示旧页面。
<?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>
上面的代码直接从我的网站取而来,并使用了较小的名称,以更改一般性并添加到您的页面中。 尝试删除其他规则并找出问题所在。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.