轉址的方式分為:
- 302: 暫時搬移 (Temporarily Moved)
- 301: 永久搬移 (Permanently Moved)
一般網頁轉址與「302 暫時搬移」
HTML
<head> <meta http-equiv=refresh content="0;url=http://host.domain.tld/path/to/"> </head>
JavaScript
<script language="JavaScript"> <!-- window.location.href = "http://host.domain.tld/path/to/"; //--> </script>
PHP
<?php header("Location: http://host.domain.tld/path/to/"); ?>
(轉址前不可有任何資料輸出)
Perl
#!/usr/bin/perl -w print "Location: http://host.domain.tld/path/to/\n\n";
(轉址前不可有任何資料輸出)
Perl - 使用 CGI 模組
#!/usr/bin/perl -w use CGI qw/:standard/; my $CGI = CGI->new(); print $CGI->redirect( -location => "http://host.domain.tld/path/to/" );
(轉址前不可有任何資料輸出)
301 永久搬移
「301 永久搬移」必須在 Server 的 Header 做宣告,因此沒有 Client 端的 HTML 或 JavaScript 語法。
PHP
<?php header("HTTP/1.1 301 Moved Permanently"); header("Location: http://host.domain.tld/path/to/"); ?>
(轉址前不可有任何資料輸出)
Perl
#!/usr/bin/perl -w print "Status: 301 Moved Permanently\n"; print "Location: http://host.domain.tld/path/to/\n\n";
(轉址前不可有任何資料輸出)
Perl - 使用 CGI 模組
#!/usr/bin/perl -w use CGI qw/:standard/; my $CGI = CGI->new(); print $CGI->redirect( -location => "http://host.domain.tld/path/to/", -status => 301, );
(轉址前不可有任何資料輸出)
請問各要存成哪種副檔名,html 的存成 .htm 或 .html 這個沒問題,
其他的呢,可以解說的再詳盡一點嗎,謝謝
非常實用
引用通告: 幾種網頁轉址與 "301 永久搬移" 的語法 | Jaken物語
引用通告: [gaq]管理員介面中 “預設網頁" 設定所造成的報表數據影響 | Google Analytics 網站分析教學與課程規劃
引用通告: 管理員介面中 “預設網頁" 設定所造成的報表數據影響 作者:awoo | dcplus 數位行銷實戰家
引用通告: 網址重導 – 這世上 沒有偶然 只有必然