redirect subdomain to wordpress category and map its post

Viewed 28

I have multiple subdomain that I want to redirect to another subdomain at category path and map the existing post URL on the old subdomain to the new subdomain

subdomainA [301 redirect]==> newsubdomain/index.php/housing

subdomainB [301 redirect]==> newsubdomain/index.php/garden

where housing,garden is a category

all subdomain is using Wordpress and has a post structure as follows

subdomainA/index.php/housing/article/get/postid

subdomainB/index.php/garden/article/get/postid

permalink setting is set up as follows

/index.php/%category%/article/get/%postname%

htaccess setting is default one, currently is set as follows

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

my goal is to map old URL into something like this

newsubdomain/index.php/housing/article/get/postid

newsubdomain/index.php/garden/article/get/postid

so I'm trying to merge more than one subdomain into just one subdomain and map its post accordingly, any recommendation or help how to do this?

thank you

1 Answers

I will suggest you proxy your website via Cloudflare and make use of their page rules for this. Cloudflare's page rules allow you to easily create 301 redirects while keeping the path.

If your old domain where the two subdomains are coming from is proxied on Cloudflare, then you just need to create these page rules;

1. Matching URL subdomainA/index.php/housing/* Settings: Forwarding URL - 301 redirect Enter the value as https://newsubdomain/index.php/housing/$1.

2. Matching URL subdomainB/index.php/garden/* Settings: Forwarding URL - 301 redirect Enter the value as https://newsubdomain/index.php/garden/$1.

Note that using this will only work if both old subdomains and new subdomain categories have similar post permalink structures.

You can read more about Cloudflare page rules here

Related