Php 在wordpress中从域重定向到类别
我正在运行一个多站点WoprdPress安装,我已将安装配置为使用子域 我已经注册并添加了一个域-a,这是我的主要网站 我最近注册了两个主要域,域a和域c,我已经指出了它们的DNS记录我的多站点的IP地址 我需要kazisport.co.za和kazisportsoccer.co.za重定向到phakathi.co.za中的一个类别 i、 e: kazisport.co.za和kazisportsoccer.co.za 重定向到: 我尝试的第一个选项是在我的多站点网络中创建第二个站点,并将这两个域映射到该站点。然后我启动了一个主题。在主题中,我使用PHP重定向代码重定向到域a中的类别,如下所示:Php 在wordpress中从域重定向到类别,php,wordpress,apache,.htaccess,redirect,Php,Wordpress,Apache,.htaccess,Redirect,我正在运行一个多站点WoprdPress安装,我已将安装配置为使用子域 我已经注册并添加了一个域-a,这是我的主要网站 我最近注册了两个主要域,域a和域c,我已经指出了它们的DNS记录我的多站点的IP地址 我需要kazisport.co.za和kazisportsoccer.co.za重定向到phakathi.co.za中的一个类别 i、 e: kazisport.co.za和kazisportsoccer.co.za 重定向到: 我尝试的第一个选项是在我的多站点网络中创建第二个站点,并将这两个
<?php
if($_SERVER['HTTP_HOST'] == 'domain-b.co.za' || $_SERVER['HTTP_HOST'] == 'domain-c.co.za')
{
header("Location: http://domain-a.co.za/category/sport/");
exit;
}
?>
<html>
<head>
<script>
function gotoPage()
{
var dns1 = "domain-b.co.za";
var dns2 = "domain-c.co.za";
var urlloc = location.href;
var loc = urlloc.toLowerCase();
if (loc.indexOf(dns1) != -1){
location.href="http://domain-a.co.za/category/sport/";
}
else if (loc.indexOf(dns2) != -1){
location.href="http://domain-a.co.za/category/sport/";
}
}
</script>
<body onLoad="gotoPage()">
</body>
</html>
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^domain-b.co.za$
RewriteRule ^$ http://domain-a.co.za/category/sport/$1 [L,R=301]
RewriteRule ^(server-info|server-status) - [L]
RewriteRule ^index\.php$ - [L]
# add a trailing slash to /wp-admin
RewriteRule ^wp-admin$ wp-admin/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^(wp-(content|admin|includes).*) $1 [L]
RewriteCond %{REQUEST_URI} !^/php5.fastcgi/*
RewriteRule ^(.*\.php)$ $1 [L]
RewriteCond %{REQUEST_URI} !^/php5.fastcgi/*
RewriteRule . index.php [L]
</IfModule>
# END WordPress
从某种意义上说,这导致了一次命中和未命中,即重定向有时有效,有时无效
然后我用JavaScript替换PHP重定向代码,如下所示:
<?php
if($_SERVER['HTTP_HOST'] == 'domain-b.co.za' || $_SERVER['HTTP_HOST'] == 'domain-c.co.za')
{
header("Location: http://domain-a.co.za/category/sport/");
exit;
}
?>
<html>
<head>
<script>
function gotoPage()
{
var dns1 = "domain-b.co.za";
var dns2 = "domain-c.co.za";
var urlloc = location.href;
var loc = urlloc.toLowerCase();
if (loc.indexOf(dns1) != -1){
location.href="http://domain-a.co.za/category/sport/";
}
else if (loc.indexOf(dns2) != -1){
location.href="http://domain-a.co.za/category/sport/";
}
}
</script>
<body onLoad="gotoPage()">
</body>
</html>
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^domain-b.co.za$
RewriteRule ^$ http://domain-a.co.za/category/sport/$1 [L,R=301]
RewriteRule ^(server-info|server-status) - [L]
RewriteRule ^index\.php$ - [L]
# add a trailing slash to /wp-admin
RewriteRule ^wp-admin$ wp-admin/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^(wp-(content|admin|includes).*) $1 [L]
RewriteCond %{REQUEST_URI} !^/php5.fastcgi/*
RewriteRule ^(.*\.php)$ $1 [L]
RewriteCond %{REQUEST_URI} !^/php5.fastcgi/*
RewriteRule . index.php [L]
</IfModule>
# END WordPress
这也导致了肇事逃逸。有时重定向会起作用,有时则不起作用。
然后我尝试了htaccess重定向,如下所示:
<?php
if($_SERVER['HTTP_HOST'] == 'domain-b.co.za' || $_SERVER['HTTP_HOST'] == 'domain-c.co.za')
{
header("Location: http://domain-a.co.za/category/sport/");
exit;
}
?>
<html>
<head>
<script>
function gotoPage()
{
var dns1 = "domain-b.co.za";
var dns2 = "domain-c.co.za";
var urlloc = location.href;
var loc = urlloc.toLowerCase();
if (loc.indexOf(dns1) != -1){
location.href="http://domain-a.co.za/category/sport/";
}
else if (loc.indexOf(dns2) != -1){
location.href="http://domain-a.co.za/category/sport/";
}
}
</script>
<body onLoad="gotoPage()">
</body>
</html>
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^domain-b.co.za$
RewriteRule ^$ http://domain-a.co.za/category/sport/$1 [L,R=301]
RewriteRule ^(server-info|server-status) - [L]
RewriteRule ^index\.php$ - [L]
# add a trailing slash to /wp-admin
RewriteRule ^wp-admin$ wp-admin/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^(wp-(content|admin|includes).*) $1 [L]
RewriteCond %{REQUEST_URI} !^/php5.fastcgi/*
RewriteRule ^(.*\.php)$ $1 [L]
RewriteCond %{REQUEST_URI} !^/php5.fastcgi/*
RewriteRule . index.php [L]
</IfModule>
# END WordPress
那根本不起作用。我不知所措,我不知道我需要做什么重定向到工作。如果有任何反馈,我将不胜感激
哦,我需要提到的是,我正在使用Varnish缓存。您可能会有一个名为的插件。安装插件后,转到: 工具->重定向 在源URL框中添加 在目标URL框中添加 接下来单击AddRedirection按钮,旧页面应该重定向到新页面。 对其他站点执行相同的操作。 免责声明:上述方法适用于单个站点,但在多站点上可能会有不同的效果