Php,jsp,.Net,.htaccess永久重定向

2010-04-22
  • 1307
  • 0

www.mywebsite.com 与www.mywebsite.com/index.php 在搜索引擎看来是两个页面相同内容,那我们可以用永久重定向来处理这个问题。

Php代码:

Header( “HTTP/1.1 301 Moved Permanently” );

Header( “Location: http:// www.mywebsite.com” );

Jsp代码

response.setStatus(301);

 response.setHeader( "Location", "http://www.mywebsite.com " );

 response.setHeader( "Connection", "close" );

 

ASP .NET代码

<script runat=”server”>

private void Page_Load(object sender, System.EventArgs e )

  {

  Response.Status = “301 Moved Permanently”;

  Response.AddHeader(”Location”,”http://www.mywebsite.com”);

  }

</script>

 

如果你有修改服务器配置文件的权限,或者有提供此功能,可以使用htaccess

.htaccess

# 将网页index.php重定向到http://www.mywebsite.com

Redirect permanent /index.php http://www.mywebsite.com