通过合理地配置重定向参数中的正则表达式,可以实现更复杂的匹配。有兴趣的朋友可参考本站Apache手册。
PHP下的301重定向
<?
Header( "HTTP/1.1 301 Moved Permanently" ) ;
Header( "Location: http://www.chineseseo.com/" );
?
ASP下的301重定向
<%@ Language=VBScript %>
<%
Response.Status="301 Moved Permanently"
Response.AddHeader "Location","http://www.chineseseo.com/"
%>
ASP .NET下的301重定向
<script runat="server">
private void Page_Load(object sender, System.EventArgs e)
{
Response.Status = "301 Moved Permanently";
Response.AddHeader ("Location","http://www.chineseseo.com/");
}
</script>
ColdFusion下的301重定向
<.cfheader statuscode="301" statustext="Moved permanently">
<.cfheader name="Location" value="http://www.new-url.com">
旧域名重定向到新域名
创建一个.htaccess文件,并将下面提供的代码写入文件内,它可以确保旧域名所有的目录或者网页正确的跳转到新域名内。
记住.htaccess文件一定要放在旧网站的根目录下,并且新网站要和旧网站保持相同的目录结构及网页文件
Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) http://www.domain.com/$1