资讯中心

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

  

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

 

html
 
<meta http-equiv="refresh" content="3; url=http://www.new-url.com/">

 

 

php
 

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

 

 

asp
 
Response.Status="301 Moved Permanently"
Response.AddHeader "Location","http://www.new-url.com/"

 

-ASP.NET Redirect:

 

asp.net
 
private void Page_Load(object sender, System.EventArgs e)
{
Response.Status = "301 Moved Permanently";
Response.AddHeader("Location","http://www.new-url.com");
}

 

 

jsp
 
response.setStatus(301);
response.setHeader( "Location", "http://www.new-url.com/" );
response.setHeader( "Connection", "close" );

 

 

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

 

 

ruby
 
def old_action
headers("Status") = "301 Moved Permanently"
redirect_to "http://www.new-url.com/"
end

 

 

javascript
 
window.location.href='http://www.newdomain.com/';

 

 

在 Internet 服务管理器中右击你想要重定向的文件和文件夹,选择 "a redirection to a URL". 然后输入目标网址,选中 "The exact url entered above"