天天看點

Adios表示再見–浏覽器301以所有語言重定向

Browser redirects, especially 301 "permanent" redirects, are essential to all good web applications. Regardless of language, browser redirects can:

浏覽器重定向,尤其是301個“永久”重定向,對于所有良好的Web應用程式都是必不可少的。 無論使用哪種語言,浏覽器重定向都可以:

  • provide safe URL forwarding to gather GET and POST variables and process them without risking data and processing integrity by a browser refresh

    提供安全的URL轉發以收集GET和POST變量并處理它們,而不會因浏覽器重新整理而冒着資料和處理完整性風險的危險

  • send users and search engine bots to the new location of a page or entire website

    将使用者和搜尋引擎漫遊器發送到頁面或整個網站的新位置

  • maintain search engine rank and avoid 404 errors

    維持搜尋引擎排名并避免404錯誤

Here's the list of browser redirects using various languages:

以下是使用各種語言進行的浏覽器重定向的清單:

.htaccess (.htaccess)

ASP (ASP)

Response.Status="301 Moved Permanently";
Response.AddHeader("Location","http://www.davidwalsh.name/");           

ASP.NET (ASP.NET)

<script runat="server">
private void Page_Load(object sender, System.EventArgs e)
{
Response.Status = "301 Moved Permanently";
Response.AddHeader("Location","http://www.davidwalsh.name");
}
</script>
           

ColdFusion (ColdFusion)

<CFHEADER statuscode="301" statustext="Moved Permanently">
<CFHEADERname="Location" value="http://www.davidwalsh.name">           

Javascript(不是301)

(Javascript (NOT a 301)

)

Java JSP (Java JSP)

response.setStatus(301);
response.setHeader("Location", "http://www.davidwalsh.name/");
response.setHeader("Connection", "close");           

元标記(不是301) (Meta tag (NOT a 301))

Perl (Perl)

use strict;
print "Status: 301 Moved Permanantlyn";
print "Location: http://www.davidwalsh.name";
exit;           

PHP (PHP)

header('HTTP/1.1 301 Moved Permanently');
header('Location: http://www.davidwalsh.name');           

Ruby On Rails (Ruby On Rails)

def old_action
headers["Status"] = "301 Moved Permanently"
redirect_to "http://www.davidwalsh.name/"
end           

Do you have any more redirect scripts? If so, post them below!

您還有其他重定向腳本嗎? 如果是這樣,請将其張貼在下面!

翻譯自: https://davidwalsh.name/browser-301-redirects