相比较IIS服务器的301重定向来说,Apache实现起来要比IIS简单多了。在Apache中,有个很重要的文件.htaccess,通过对它的设置,可以实现很多强大的功能,301重定向只是其中之一。
Redirect permanent / http://blog.youxibo.com/ ;将目录下内容重定向到http://blog.youxibo.com/
redirect permanent /old.html http://blog.youxibo.com/new-url/ ;将网页old.html内容重定向到http://blog.youxibo.com/new-url/
通过合理地配置重定向参数中的正则表达式,可以实现更复杂的匹配。有兴趣的朋友可参考Apache手册。
其他方法还有:
PHP下的301重定向
<? Header( “HTTP/1.1 301 Moved Permanently” );
Header( “Location: http://blog.youxibo.com” );?>
ASP下的301重定向
<%@ Language=VBScript %>
<% Response.Status=”301 Moved Permanently” Response.AddHeader “Location”, ” http://blog.youxibo.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://blog.youxibo.com”);
}
</script>