apache 重定向(301)到新域名

Apache下301重定向代码(由于我使用的是WINDOWS 2003 + APACHE 因此本文仅限APACHE服务器使用。)php

新建.htaccess文件,输入下列内容(须要开启mod_rewrite):html

1)将不带WWW的域名转向到带WWW的域名下服务器

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^163.com [NC]
RewriteRule ^(.*)$ http://www.163.com/$1 [L,R=301]spa

2)重定向到新域名htm

Options +FollowSymLinks
RewriteEngine on
RewriteRule ^(.*)$ http://www.001.com/$1 [L,R=301]域名

3)使用正则进行301重定向,实现伪静态it

Options +FollowSymLinks
RewriteEngine on
RewriteRule ^news-(.+)\.html$ news.php?id=$1io

将news.php?id=123这样的地址转向到news-123.html配置

Apache下vhosts.conf中配置301重定向规范化

为实现URL规范化,SEO一般将不带WWW的域名转向到带WWW域名,vhosts.conf中配置为:

<VirtualHost *:80>
ServerName www.001.com
DocumentRoot /home/fari001Com
</VirtualHost>

<VirtualHost *:80>ServerName fari001.comRedirectMatch permanent ^/(.*) http://www.001.com/$1</VirtualHost>

相关文章
相关标签/搜索