转址的方式分为:
- 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 数位行销实战家
引用通告: 网址重导 – 这世上 没有偶然 只有必然