301重定向(apache/php)
apache
1.httpd.conf中,找到
<Directory />
Options FollowSymLinks
AllowOverride None
把其中的AllowOverride None改为AllowOverride All,然后重启apache
2.网站根目录新建.htaccess文件输入下面代码
1)将不带WWW的域名转向到带WWW的域名下
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^****.cn [NC]
RewriteRule ^(.*)$ http://www.****.cn/$1 [L,R=301]
2)重定向到新域名
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^(.*)$ http://www.****.cn/$1 [L,R=301]
3)使用正则进行301转向,实现伪静态
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^news-(.+)\.html$ news.php?id=$1
将news.php?id=123这样的地址转向到news-123.html
============================================
PHP
<?php
Header( "HTTP/1.1 301 Moved Permanently" ) ;
Header( "Location: http://www.****.com" );
exit();
?>
============================================
http://www.seoconsultants.com/tools/headers.asp 到这里查看下设置是否有效
相关文章:
- Quotation
- CommentsFeed
- Tags: 301
- Quot: 0
- Tour:
Feedback
◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。