如何使用Web配置文件添加301重定向? [英] How to add 301 Redirect using web config file ?

查看:117
本文介绍了如何使用Web配置文件添加301重定向?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我设计了一个网站Sapphire Enterprises

我想301重定向到 http://sapphireenterprises.net/default.aspx [ ^ ] http://sapphireenterprises.net/ [ ^ ]

因为它会产生重复的内容问题。为此我在web配置文件中添加以下代码



< system.webserver>







< rewrite>



< rule name =Canonical Host Namestopprocessing =true> ;

< rule name =Strip Default.aspx Out>

< match url =(。*)default.aspxignorecase =false >

< action type =Redirecturl ={R:1}redirecttype =Permanent>















但有是重写下方的蓝色下划线,代码无效。



我从这篇文章中得到了这个想法

http://www.4guysfromrolla .com / articles / 072810-1.aspx



但是没有用。请帮我。我正在使用visual studio 2008并安装了IIS URL重写模块2.

Hi,
I have designed a website Sapphire Enterprises
I want 301 redirect to http://sapphireenterprises.net/default.aspx[^] to http://sapphireenterprises.net/[^]
as it is creating duplicate content issue. For that I add following code in web config file

<system.webserver>



<rewrite>

<rule name="Canonical Host Name" stopprocessing="true">
<rule name="Strip Default.aspx Out">
<match url="(.*)default.aspx" ignorecase="false">
<action type="Redirect" url="{R:1}" redirecttype="Permanent">







but there is blue underline below rewrite and the code is not working.

I got the idea from this post
http://www.4guysfromrolla.com/articles/072810-1.aspx

But is not working. Please help me. I am using visual studio 2008 and installed IIS URL rewrite Module 2 also.

推荐答案

在旧页面的文件夹中,添加一个Web.Config文件并将其放入配置标签:

In the folder of your old page, add a Web.Config file and put this in the configuration tag:
<location path="old.aspx">
  <system.webServer>
    <httpRedirect enabled="true" destination="new.aspx" httpResponseStatus="Permanent" />
  </system.webServer>
</location>



重要提示:目的地必须是相对于old.aspx 的路径。如果要使其相对于Web服务器的根目录,请确保它以斜杠开头。


Important: destination has to be a path relative to old.aspx. If you want to make it relative to the root of the web server, make sure it starts with a slash.


这篇关于如何使用Web配置文件添加301重定向?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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