Redirecting from domain to category
-
I am running a multisite WoprdPress install where I have configured my install to use sub-domains.
I have registered and added one domain domain-a.co.za which is my main site.
I have recently registered two main domains, domain-a.co.za and domain-c.co.za, and I have pointed their DNS records IP address of my multisite.
I need domain-b and domain-c to redirect to a category in domain-a.
i.e:
https://domain-b.co.za and https://domain-c.co.za
redirect to:
https://domain-a/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 if($_SERVER['HTTP_HOST'] == 'domain-b.co.za' || $_SERVER['HTTP_HOST'] == 'domain-c.co.za') { header("Location: https://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:<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="https://domain-a.co.za/category/sport/"; } else if (loc.indexOf(dns2) != -1){ location.href="https://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:# BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteCond %{HTTP_HOST} ^domain-b.co.za$ RewriteRule ^$ https://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.
- The topic ‘Redirecting from domain to category’ is closed to new replies.