【发布时间】:2015-01-24 18:08:25
【问题描述】:
我在应用程序根目录中有一个单独的.config 文件,其中包含Mapped URLS for redirect,并在web.config 中为301 Permanent Redirect 引用了这个.config 文件!这工作正常。
现在,我还想添加一些将重定向为 302 状态代码的链接。如何在外部 .config 文件中添加 302 重定向并进行相应的重定向。
rewritemaps.config
<rewriteMaps>
<rewriteMap name="Redirects">
<add key="/oldcellphone" value="/newcellphones.aspx" />
</rewriteMap>
</rewriteMaps>
我们可以在这个文件中指定重定向类型,即 301/302 吗?
web.config
<system.webServer>
<rewrite>
<rewriteMaps configSource="rewritemaps.config">
</rewriteMaps>
<rules>
<rule name="Redirect rule1 for Redirects">
<match url=".*" />
<conditions>
<add input="{Redirects:{REQUEST_URI}}" pattern="(.+)" />
</conditions>
<action type="Redirect" url="{C:1}" appendQueryString="false" redirectType="Permanent"/>
</rule>
</rules>
</rewrite>
</system.webServer>
注意:目前来自文件'rewritemaps.config' 的所有链接都设置为web.config 中的301 Status。
我们能否在 rewritemaps.config 中添加如下内容并进行相应的重定向:
<add key="/oldcellphone" value="/newcellphones.aspx" [RedirectType=301] />
<add key="/oldphone" value="/newphones.aspx" [RedirectType=302] />
大约有1000 links of 301 Status 和大约400 links for 302 Status。如果在external file(rewritemaps.config) 中不可能,那么请建议首选方法?
更新: 如果请求的 URL 中的特定字符串匹配,你能帮我重定向到另一个站点(不同的域)吗? 例如:如果请求的 URL 包含“/hm1”,则重定向到不同的站点。即http://www.google.com
Web.config
<rule name="othersite" stopProcessing="true">
<match url="^/hm1$" />
<action type="Redirect" url="http://www.google.com" redirectType="Found"/>
</rule>
.aspx
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="/hm1">other site (http://www.google.com)</asp:HyperLink>
【问题讨论】:
标签: redirect web-config http-status-code-301 http-status-code-302