將多個域名301重定向至一個域名服務器
添加訪問域名的DNS記錄,使之能解析至同一服務器;ide
修改httpd的配置,容許網站目錄下的.htaccess配置覆蓋httpd的配置;網站
編輯.htaccess,配置重定向域名。ui
Example:使www.oimec.com.cn、www.oimec.cn、www.jicheng.cn 三個域名301重定向至www.jicheng.net.cnspa
修改DNS,添加www.oimec.com.cn、www.oimec.cn、www.jicheng.cn域名的CNAME記錄至www.jicheng.net.cn。.net
修改httpd的配置文件:3d
<VirtualHost *:80> ServerAdmin admin@abc.com ServerName www.jicheng.net.cn ServerAlias www.jicheng.cn www.oimec.com.cn www.oimec.cn DocumentRoot /data/htdocs/jicheng <Directory "/data/htdocs/jicheng/"> Options FollowSymLinks AllowOverride All #啓用網站目錄下的.htaccess,使之生效 Require all granted </Directory> </VirtualHost>
在網站目錄下添加.htaccess文件,內容以下:orm
RewriteEngine On # www.oimec.com.cn www.oimec.cn www.jicheng.cn redirect to www.jicheng.net.cn RewriteBase /data/htdocs/jicheng/ RewriteCond %{HTTP_HOST} ^www.oimec.com.cn [OR] RewriteCond %{HTTP_HOST} ^www.oimec.cn [OR] RewriteCond %{HTTP_HOST} ^www.jicheng.cn [NC] RewriteRule ^(.*)$ http://www.jicheng.net.cn/$1 [L,R=301]
驗證:blog