Home > Backend Development > PHP Tutorial > 更换域名301跳转有关问题

更换域名301跳转有关问题

WBOY
Release: 2016-06-13 10:24:41
Original
858 people have browsed it

求助 更换域名301跳转问题
假设老域名: a.com ,新域名: b.com 

请教如何配置.htaccess,将原域名所有URL 301跳转到新域名,包括二级域名
如:www.a.com -> www.b.com
a.com -> www.b.com
shop.a.com -> shop.b.com
photo.a.com -> photo.b.com
...................... 等等


我在 .htaccess添加了以下规则,会把所有URL转向到www.b.com ,无法满足要求

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d

RewriteCond %{HTTP_HOST} (.*)a.com [NC]
RewriteRule ^(.*)$ http://www.b.com/$1 [R=301,NC]


注:服务器环境 Apache + PHP

------解决方案--------------------
你试着加点:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^[^\.]+\.a\.com$
RewriteRule ^(.*) %{HTTP_HOST}/$1 [C]
RewriteRule ^([^\.]+)\.a\.com(.*)$ http://$1\.b\.com$2\?%{QUERY_STRING} [R=301,L]

这样加个/好不好用呢。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template