首页 电脑 电脑学堂 查看内容

301重定向代码大全

2011-9-29 22:33 649 0

摘要:   1、PHP 301 重定向代码header(”HTTP/1.1 301 Moved Permanently”);  header(”Location: http://www.mvpec.com/a...
关键词: 定向 HTTP com www 301 代码 mvpec permanent 域名 hxj

  1、PHP 301 重定向代码header(”HTTP/1.1 301 Moved Permanently”);  header(”Location: http://www.mvpec.com/articles/301/”);  exit();  2、Apache301 重定向代码新建。htaccess文件,输入下列内容(需要开启mod_rewrite):1)将不带WWW的域名转向到带WWW的域名下Options +FollowSymLinks  RewriteEngine on  RewriteCond %{HTTP_HOST} ^mvpec.com [NC]  RewriteRule ^(.*)$ http://www.mvpec.com/$1 [L,R=301]  2)重定向到新域名Options +FollowSymLinks  RewriteEngine on  RewriteRule ^(.*)$ http://www.mvpec.com/$1 [L,R=301]  3)使用正则进行301转向,实现伪静态Options +FollowSymLinks  RewriteEngine on  RewriteRule ^news-(.+)\.html$ news.php?id=$1  将news.php?id=123这样的地址转向到news-123.html  3、ASP 301重定向代码<%@ Language=VBScript %>  <%  Response.Status=”301 Moved Permanently”  Response.AddHeader “Location”, “http://www.mvpec.com/articles/301/”  %>  4、ASP.Net 301重定向代码<script runat=”server”>  private void Page_Load(object sender, System.EventArgs e)  {  Response.Status = “301 Moved Permanently”;  Response.AddHeader(”Location”,”http://www.mvpec.com/articles/301/“);  }  </script>  5、Apache下vhosts.conf中配置301转向为实现URL规范化,SEO通常将不带WWW的域名转向到带WWW域名,vhosts.conf中配置为:<VirtualHost *:80>  ServerName www.mvpec.com  DocumentRoot /home/mvpec  </VirtualHost>  <VirtualHost *:80>  ServerName lesishu.cn  RedirectMatch permanent ^/(.*) http://www.mvpec.com/$1  </VirtualHost>  6、JSP 301重定向代码<%  response.setStatus(301);  response.setHeader( “Location”, “http://www.mvpec.com/” );  response.setHeader( “Connection”, “close” );  %>  7、CGI Perl 301重定向代码$q = new CGI;  print $q->redirect(”http://www.new-url.com/”);  8、nginx 301重定向代码把www.hxj.com和hxj.com合并,并把之前的域名也一并合并。 有两种实现方法,第一种方法是判断nginx核心变量host(老版本是http_host):  server {  server_name www.hxj.com hxj.com ;  if ($host != 'www.hxj.com' ) {  rewrite ^/(.*)$ http://www.hxj.com/$1 permanent;  }  …  }  第二种方法:  server {  server_name hxj.com;  rewrite ^/(.*) http://www.hxj.com/$1 permanent;  }  这两种方法中, permanent是关键,详细说明见nginx重定向规则说明。  last – 基本上都用这个Flag。  break – 中止Rewirte,不在继续匹配  redirect – 返回临时重定向的HTTP状态302  permanent – 返回永久重定向的HTTP状态301  301转向情况检测http://www.seoconsultants.com/tools/headers.asp  http://www.internetofficer.com/seo-tool/redirect-check/
声明:文章版权归原作者所有 部分文章转自互联网 如有侵权请联系 [邮箱地址] 删除

路过

雷人

握手

鲜花

鸡蛋

最新评论

返回顶部