重定向的所有页面,包括子页面到新的域名

问题描述:

我尝试这样做:重定向的所有页面,包括子页面到新的域名

RedirectMatch 301 (.*) http://olddomain.com$1 
RewriteEngine On 
RewriteBase/
RewriteCond %{HTTP_HOST} ^olddomain.com$ [NC] 
RewriteRule ^(.*)$ http://newdomain.com/$1 [L,R=301] 

但所有子网页不重定向。

您是否在您的Apache配置中设置了指令AllowOverride All? mod_rewrite模块是否工作?

+0

请注意'AllowOverride All'只在apache 2.2及更旧的版本上 – rekire

试试这个,

RewriteEngine On 
# Take care of www.old.com.au 
RewriteCond %{HTTP_HOST} ^www.old.com.au$ [NC] 
RewriteRule ^(.*)$ http://www.new.com/$1 [L,R=301] 
RewriteCond %{QUERY_STRING} ^attachment_id=([0-9]*)$ [NC] 
RewriteRule ^$ http://www.new.com/? [R=301,NE,NC,L] 

这很简单,我只是用这个做一些特别改写为我自己,这是你的代码:

将这个你/www/.htaccess文件中:

RewriteEngine on 

// Rules to redirect to another domain 
RewriteCond %{HTTP_HOST} ^example.com [NC,OR] 
RewriteCond %{HTTP_HOST} ^www.example.com [NC] 
RewriteRule ^(.*)$ http://example.net/$1 [L,R=301,NC] 

检查http://www.inmotionhosting.com/support/website/redirects/setting-up-a-301-permanent-redirect-via-htaccess,获取3种其他方式进行重定向。