如何做301转向


301 redirect: 301代表永久性转移(Permanently Moved),301重定向是网页更改地址后对搜索引擎友好(SEO)的最好方法,只要不是暂时搬移的情况,都建议使用301来做转址。

现在知道的有2类,一类是在web服务软件上做,还有就是在程序里面做

先说在web服务软件

如果是iis:
打开internet信息服务管理器,在要重定向的网页或目录上按右键

  1. 选中“重定向到URL”
  2. 在对话框中输入目标页面的地址
  3. 选中“资源的永久重定向”
  4. 点击“应用

如果是apache方法多一些,也方便一些
如果要把访问www.juhui.com的请求全部301到www.juyimeng.com
[code linenum=”off”]

Redirect 301 / http://www.juyimeng.com/
CustomLog logs/redir “%h %l %u %t \”%r\” %>s %b \”%{Referer}i\” \”%{User-agent}i\””
[/code]上面的
Redirect 301 / http://www.juyimeng.com/
可以写为
Redirect permanent / http://www.juyimeng.com/

也可以用apache的.htaccess,怎么使.htaccess起效,点这里
.htaccess文件的内容
[code linenum=”off”]RewriteEngine on
rewriterule abc\.html /index\.html [R=301]
[/code]
其总用是把abc.html301到index.html

用程序来做

用PHP来做301重定向
[code lang=”php” linenum=”off”] [/code]

用JSP (Java)来做301重定向
[code lang=”java” linenum=”off”]<% response.setStatus(301); response.setHeader( "Location", "http://www.test.com/" ); response.setHeader( "Connection", "close" ); %> [/code]

用CGI PERL 来做301重定向

[code lang=”perl” linenum=”off”]$q = new CGI;
print $q->redirect(“http://www.test.com/”); [/code]

用ASP来做301重定向

[code lang=”” linenum=”off”]
<%@ Language=VBScript %>
<% Response.Status="301 Moved Permanently"; Response.AddHeader("Location","http://www.test.com/"); %> [/code]
用ColdFusion 来做301重定向

[code lang=”” linenum=”off”]<.cfheader statuscode="301" statustext="Moved permanently">
<.cfheader name="Location" value="http://www.test.com"> [/code]用ASP .NET Redirect来做301重定向

[code lang=”” linenum=”off”] [/code]

用Ruby on Rails Redirect来做301重定向

[code lang=”” linenum=”off”]def old_action
headers[“Status”] = “301 Moved Permanently”
redirect_to “http://www.test.com/”
end [/code]

html的meta refresh和javascript也可以转向

[code lang=”html” linenum=”off”]

[/code]

但是上述的方法不推荐

如果要Redirect的源url是html这种结尾也可以,改apache的配置,把html扩展名的文件当Php或者其他脚本来处理就可以了
AddType application/x-httpd-php .html
AddType application/x-httpd-php .htm

上述改造是否成功,可以用httpwatch来查看


发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注