简体   繁体   English

WordPress的多域重定向不起作用

[英]Wordpress Multiple Domain Redirect Not Working

I have any problem on my wordpress site. 我在wordpress网站上有任何问题。 My wordpress site's new domain is (ex:) "www.domain.com" and last domain is "www.domain2.com". 我的wordpress网站的新域是(例如:)“ www.domain.com”,最后一个域是“ www.domain2.com”。 I assigned new domain's nameserver address to old domain's nameserver address. 我将新域的名称服务器地址分配给了旧域的名称服务器地址。 But not working rewrite rule when entering old domain. 但是在进入旧域时无法使用重写规则。 My rule is: 我的规则是:

RewriteCond %{HTTP_HOST} ^domain2.com$ [NC]
RewriteCond %{REQUEST_URI} ^/(.*)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ https://domain.com/hello/$1 [L,R=301]

An easy solution may be to put this at the top of your theme's header.php file: 一个简单的解决方案是将其放在主题的header.php文件的顶部:

<?php
Header( "HTTP/1.1 301 Moved Permanently" );
Header( "Location: http://www.new_site.com");
?>

You could also do this conditionally based off the requested URI, so only certain URLs get redirected: 您还可以根据请求的URI有条件地执行此操作,因此仅某些URL被重定向:

<?php
if ( $_SERVER['REQUEST_URI'] == 'certain url' ) {
    Header( "HTTP/1.1 301 Moved Permanently" );
    Header( "Location: http://www.new_site.com");
}
?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM