首页 > SEO技术 > 301 Redirect 永久重定向的实现

301 Redirect 永久重定向的实现

作者:highdiy 时间:2006年10月9日


常用的重定向方式有: 301 redirect, 302 redirect 与 meta fresh:

  • 301 redirect: 301代表永久性转移(Permanently Moved),301重定向是网页更改地址后对搜索引擎友好的最好方法,只要不是暂时搬移的情况,都建议使用301来做转址。
  • 302 redirect: 302代表暂时性转移(Temporarily Moved ),在前些年,不少Black Hat SEO曾广泛应用这项技术作弊,目前,各大主要搜索引擎均加强了打击力度,象Google前些年对Business.com以及近来对BMW德国网站的惩罚。即使网站客观上不是spam,也很容易被搜寻引擎容易误判为spam而遭到惩罚。
  • meta fresh: 这在2000年前比较流行,不过现在已很少见。其具体是通过网页中的meta指令,在特定时间后重定向到新的网页,如果延迟的时间太短(约5秒之內),会被判断为spam。

这里我们主要谈谈如何通过301 Redirect实现网页重定向


* 打开internet信息服务管理器,在欲重定向的网页或目录上按右键,见下图
* 选中“重定向到URL”
* 在对话框中输入目标页面的地址
* 切记,记得选中“资源的永久重定向”
* 当然,最后要点击“应用”



Redirect permanent / http://seo.highdiy.com/ ;将目录下内容重定向到http://seo.highdiy.com/
redirect permanent /old.html http://seo.highdiy.com/new-url/ ;将网页old.html内容重定向到http://seo.highdiy.com/new-url/




<? Header( "HTTP/1.1 301 Moved Permanently" );
Header( "Location: http://seo.highdiy.com" );?>


<%@ Language=VBScript %>
<% Response.Status=”301 Moved Permanently” Response.AddHeader “Location”, ” http://seo.highdiy.com”>

ASP .NET下的301重定向

<script runat=”server”>
private void Page_Load(object sender, System.EventArgs e)
Response.Status = “301 Moved Permanently”;

配置完成后,要认真检查一下是否正确。Internet有很多类似的Server Header检查工具,如Check Server Headers Tool - HTTP Status Codes Checker或本站提供的这个网页重定向检查工具。

作者: highdiy
原载: 点石互动搜索引擎优化博客



  1. Simon
    2006年10月9日16:59 | #1


    301 Redirects & Canonical URL Issues Tutorial
    Registered ©2006 SEO Image, Inc

    When you move a file on your server you want to be certain that you pass the proper redirect directive to the browsers and more importantly, the Search Engines. The 301 redirect is the only redirect we recommend for anyone o use without advanced knowledge of using redirects. 302 redirects are actually used by SEO's for some specific reasons such as moving domain names from an old domain.com to a new domain.com

    301 Redirects & Canonical Redirects for Apache
    This is done on the invisible file named ".htaccess" this file is located in the root of your Web Server.
    For a single page redirect (NEVER use a 302 make sure it says either "Permanent" or "301" in the file if it doesn't it will pass a 302 by default:
    redirect 301 /old-file-name-html http://www.yourdomain.com/new-file.html
    redirect permanent /old-file.html http://www.yourdomain.com/new-file.html
    Notice all that is needed is one space between the old path and the new URL. The new URL must contain an Absolute URL: meaning it uses http://www.yourdomain.com/yourfile.html. If there is a space in the file name use otherwise it will not work, you can only leave one space and that is between the old file path and the new url. Here is an example:
    /old file.html http://www.yourdomain.com/new-file.html
    Apache Server Canonical Redirect
    (non-www to www):
    This should always be done as some search engines do not properly understand the difference and may count it as a duplicate page, additionally if you us domain.com/index.html or domain.com index.php the Search Engine might get lost. Since Google is the most popular Search Engine, it also happens to be the least advanced with canonical issues and redirects. Google is also in a major anti-spam battle so it would actually hurt your rankings unintentionally as its a bit archaic in its handling of canonical issues and redirects. What Google will see as the same page duplicated on your site (In reality its all the same page).
    Since Google favors penalties over relative content you need to make sure you NEVER link to your home page as "index.html" or any other file extension. The automated factors of the Google algorithm would ban you without warning, and Google makes it a policy to not notify webmasters of penalties, so you could be spending years trying to resolve an issue like this. Make all your links Absolute to a least your home page so any link on your site should always link to "http://www.yourdomain.com/" be sure to use the trailing slash as some servers will pass a redirect to the trailing slash if you do not, and this will be a 302 redirect. This is a known issue on WebStar Server a Mac Platform.

    -Not direct to the domain.
    - No Trailing Slash
    Now for the .htaccess canonical redirect for the NON-www. to the www.
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^domain\.com
    RewriteRule (.*)
    http://www.domain.com/$1 [R=301,L]
    NOTE: Some Versions of Apace require an extra line or two of code for SymLinks and a different structure of the rewrite rule as follows:

    RewriteEngine On
    Options FollowSymlinks
    RewriteBase /
    RewriteCond %{HTTP_HOST} ^domain\.com$ [NC]
    RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]
    A More advanced version will even allow you to 301 your IP address and any subdomains:
    RewriteEngine On
    RewriteCond %{HTTP_HOST} .
    RewriteCond %{HTTP_HOST} !^www\.domain\.com
    RewriteRule (.*) http://www.domain.com/$1 [R=301,L]
    The above code will 301 your non-www to your www, as well as redirect your IP address as a 301 to your www.
    To redirect your http pages but NOT your https pages use:
    Say for instance, your secure certificate was not created as http://www.domain.com, but was instead issued as domain.com then you would need to use the following and be sure to combine this with ABSOLUTE links (absolute links use the full URL), or you may unintentionally cause duplicate https and http paths.
    RewriteCond %{SERVER_PORT} ^80
    RewriteCond %{HTTP_HOST} ^domain\.com
    RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L,QSA]

    301 Redirects & Canonical Redirects:
    Microsoft IIS Web Servers
    To Perform this you need administrative access to the IIS Server Application. If you do not have this then you can do the redirects in ASP or PHP.
    Single Page Redirect:
    1. Open Internet Services Manager then "right-click" on the file or folder you want to redirect to a new page or folder.
    2. Select "redirection to a URL".
    3. Enter the URL where you want the redirect to go to.
    4. Check the fields: "exact url entered above" and "A permanent redirection for this resource".
    5. Click "Apply".
    PHP 301 Redirect
    This is added to the page that you want to redirect to a new page, it is triggered on the request for the specific page and the file will actually return the redirect.
    Single Page Redirect:

    PHP Canonical Redirect:
    (non-www to www)

    Redirects & Canonical Redirects for Active Server Pages (ASP)
    Single Page Redirect:
    This is placed on the page you are redirecting and is triggered when someone tries to access the page.

    ASP Canonical Redirect:
    (non-www to www):
    This code should be inserted into a global include file or any script which is executed for every page on the site before the page output begins. If your programmers are using ASP.net and/or they are not using a global file, you need to have them address this issue or perform the Canonical Redirect from the IIS Server Application (as above).

    301 Redirects for ASP.NET
    For Single Pages:

    private void Page_Load(object sender, System.EventArgs e)
    Response.Status = "301 Moved Permanently";

    301 Redirects for Sun Web Servers
    In order to do this on a SUN platform you have to rewrite the SUN Web Server's standard action of always using a 302 redirect to always use a 301 redirect. You have to open the obj.conf configuration file and add the following lines below the line:

    Output fn="set-variable" error="301" noaction="true"

    The above will make the SUN web server to return 301 permanent redirect responses for all redirects. If you only want to use a 301 permanent redirect response for certain URLs or files, you can add following to the bottom of obj.conf:

    Output fn="set-variable" error="301" noaction="true"

  2. Simon
  3. lyc
    2006年10月9日17:34 | #3


  4. 2006年10月10日09:39 | #4


    <%@ Language=VBScript %>
    <% Response.Status=”301 Moved Permanently” Response.AddHeader “Location”, ” http://seo.highdiy.com”>


  5. 2006年10月10日10:16 | #5

    感谢楼主 学习了

  6. 2006年10月10日12:53 | #6


  7. 2006年10月12日14:20 | #7


  8. 2007年4月20日13:30 | #8

    <%@ Language=VBScript %>
    <% Response.Status=”301 Moved Permanently” Response.AddHeader “Location”, ” http://seo.highdiy.com”>

  9. 2007年6月3日18:36 | #9


  10. 2007年6月9日09:41 | #10


  11. 2007年6月20日18:59 | #11



    比如原来多个叶面都是动态的现在转化成静态的了,应该每个叶面都重新定向到新的静态页面吗? asp的


  12. 2007年6月24日15:41 | #12

    不错啊 呵呵

  13. 2007年6月27日18:13 | #13


  14. 2007年8月20日03:38 | #14


  15. lgfifa
    2007年11月26日00:37 | #15


  16. 2008年2月11日09:53 | #16


  17. 2008年2月27日20:02 | #17


  18. 2008年5月20日01:38 | #18


  19. 海水焰
    2008年11月22日13:41 | #19


  20. 转角遇到钱
    2008年12月7日17:16 | #20


  21. 2008年12月14日16:26 | #21


  1. 2007年6月17日20:18 | #1
  2. 2007年10月17日11:33 | #2
  3. 2008年4月10日10:35 | #3