[英]Redirecting from domain to category in wordpress
I am running a multisite WoprdPress install where I have configured my install to use sub-domains. 我正在运行多站点WoprdPress安装,其中已将安装配置为使用子域。
I have registered and added one domain domain-a which is my main site.
我已经注册并添加了一个域domain-a,这是我的主站点。
I have recently registered two main domains, domain-a and domain-c, and I have pointed their DNS records IP address of my multisite.
我最近注册了两个主要域,域a和域c,并且指出了它们的DNS记录我的多站点的IP地址。
I need kazisport.co.za and kazisportsoccer.co.za to redirect to a category in phakathi.co.za. 我需要kazisport.co.za和kazisportsoccer.co.za重定向到phakathi.co.za中的类别。
ie: 即:
kazisport.co.za and kazisportsoccer.co.za kazisport.co.za和kazisportsoccer.co.za
redirect to: 重定向到:
http://phakathi.co.za/category/sport/
http://phakathi.co.za/category/sport/
The first option I tried was creating a second site in my multisite network and mapped the two domains to the site. 我尝试的第一个选项是在我的多站点网络中创建第二个站点,并将两个域映射到该站点。 Then I activated a theme.
然后,我激活了一个主题。 In the theme I used PHP redirect code to redirect to the category in domain-a like this:
在主题中,我使用PHP重定向代码将其重定向到domain-a中的类别,如下所示:
<?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;
}
?>
That resulted in a hit and miss in a sense that sometimes the redirection would work and sometimes it wouldn't work. 从某种意义上说,这导致了成功与失败,有时重定向会起作用,有时却不起作用。
Then I replaced the the PHP redirect code with JavaScript like this: 然后,我将JavaScript重定向代码替换为JavaScript,如下所示:
<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>
That also resulted in hit and miss. 这也导致了失败。 Sometimes the redirection would work and sometimes it would not work.
有时重定向将起作用,有时则将不起作用。 Then I tried htaccess redirect like this:
然后我尝试了htaccess重定向,如下所示:
# 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
That did not work at all. 那根本没有用。 I am at a loss and I do not know what I need to do for the redirection to work.
我很茫然,我不知道我需要做什么才能使重定向生效。 I would really appreciate any feedback.
我真的很感谢任何反馈。
Oh, I need to mention that I am using Varnish Cache. 哦,我要提一提的是我正在使用Varnish Cache。
You might have some luck with a plugin called Redirection . 您可能会对名为Redirection的插件感到幸运。 After installing the plugin go to:
安装插件后,请转到:
(Disclaimer: The above works on a single site, it might work differently on a multisite.) (免责声明:以上内容在单个站点上有效,在多站点上可能有所不同。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.