12种实现301网页重定向方法的代码实例

为什么需要使用301重定向: 1. 保留搜索引擎的排名: 301 重定向是最有效的方法,不会影响到搜索引擎对页面的排名。 2. 保留访客和流量: 如果你将页面链接到大量方法可以访问过的地址,如果不是用重定向的话你就会失去这些用户(不解)原文:If you move your popul...

为什么需要使用301重定向:

1. 保留搜索引擎的排名: 301 重定向是最有效的方法,不会影响到搜索引擎对页面的排名。

2. 保留访客和流量: 如果你将页面链接到大量方法可以访问过的地址,如果不是用重定向的话你就会失去这些用户(不解)原文:If you move your popular page to which a lot of visitors have already linked, you may lose them if you don't used redirect method. This provides a great way to provide your visitors with the information they were looking for and prevent you from losing your traffic.

序列号 CPU RAM HDD 带宽 售价(美元) 免费试用
香港服务器1 E5-2620 32G 1T HDD 50M/无限流量 $196.00 立即申请
香港服务器2 E5-2650 32G 1T HDD 50M/无限流量 $256.00 立即申请
香港服务器3 E5-2680 32G 1T HDD 50M/无限流量 $316.00 立即申请
香港服务器4 E5-2690 32G 1T HDD 50M/无限流量 $336.00 立即申请
香港服务器5 E5-2697 32G 1T HDD 50M/无限流量 $376.00 立即申请
香港服务器6 E5-2620*2 32G 1T HDD 50M/无限流量 $376.00 立即申请
香港服务器7 E5-2650*2 32G 1T HDD 50M/无限流量 $436.00 立即申请
香港服务器8 E5-2680*2 32G 1T HDD 50M/无限流量 $476.00 立即申请
香港服务器9 E5-2690*2 32G 1T HDD 50M/无限流量 $556.00 立即申请
香港服务器10 E5-2697*2 32G 1T HDD 50M/无限流量 $596.00 立即申请
香港服务器11 E5-2680v4*2 32G 1T HDD 50M/无限流量 $696.00 立即申请
香港服务器12 E5-2698v4*2 32G 1T HDD 50M/无限流量 $796.00 立即申请

下面是 11 中实现 301 重定向的方法:

1. HTML 重定向/Meta 刷新

将下面 HTML 重定向代码放在网页的 节点内:
 
上述代码立即将访客重定向到另外一个页面,你可以修改 content 中 的 0 这个值来表示几秒钟后才进行重定向。例如 content="3; url=http://www.oschina.net/" 表示三秒后再重定向。

2. PHP 重定向

 

复制代码

代码如下: Header( "HTTP/1.1 301 Moved Permanently" );
Header( "Location: http://www.new-url.com" );
?> 

 

3. ASP Redirect

复制代码

代码如下:
<%@ Language=VBScript %>
<%
Response.Status="301 Moved Permanently"
Response.AddHeader "Location","http://www.new-url.com/"
%>

 

4. ASP .NET Redirect

复制代码

代码如下:

 

5. JSP Redirect

复制代码

代码如下:
<%
response.setStatus(301);
response.setHeader( "Location", "http://www.new-url.com/" );
response.setHeader( "Connection", "close" );
%>

 

6. CGI PERL Redirect

复制代码

代码如下:
$q = new CGI;
print $q->redirect("http://www.new-url.com/");

 

7. Ruby on Rails Redirect

复制代码

代码如下:
def old_action
headers["Status"] = "301 Moved Permanently"
redirect_to "http://www.new-url.com/"
end

 

8. ColdFusion Redirect

复制代码

代码如下:
<.cfheader statuscode="301" statustext="Moved permanently">
<.cfheader name="Location" value="http://www.new-url.com">

 

9. Javascript URL Redirect

复制代码

代码如下:


 

10. IIS Redirect
在 Internet 服务管理器中右击你想要重定向的文件和文件夹,选择 "a redirection to a URL". 
然后输入目标网址,选中 "The exact url entered above" 和 "A permanent redirection for this resource" 然后点击 'Apply' 按钮。

11. 使用 .htaccess 进行重定向

创建一个 .htaccess 文件(代码如下)用来将访问呢 domain.com 重定向到 www.domain.com 下,该文件必须放置在网站的root目录,也就是首页放置的目录。

 

复制代码

代码如下: Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^domain.com [nc]
rewriterule ^(.*)$ http://www.domain.com/$1 [r=301,nc]

 

注意: .htaccess 方法的重定向只能在 Linux 下使用 Apache 的 mod_rewrite 模块启用的情况下使用。

12.Nginx中的rewrite

 

复制代码

代码如下:
server {
    server_name www.jb51.net jb51.net;
    if ($host = 'jb51.net' ) {
        rewrite ^/(.*)$ http://www.jb51.net/$1 permanent;
}  

(责任编辑:joker) 部分网站内容及图片来源于网络,如有侵权或违规内容请联系管理员删除!


 

TAG: 宋体代码重定向方法访客页面

  • Tg①
  • Tg②