How to make every page in a blog canonical to another site with the same url structure

Joined
Feb 16, 2019
Messages
65
Likes
32
Degree
0
I have a bit of a weird situation. I have a Wordpress site that I recently acquired that has some rankings already, but it has a MAJOR issue. both the subdomain and subfolder work site.com/blog and blog.site.com both load the same site, which is a major duplicate content issue. Some posts rank on one site, some rank for the other. It's a mess.

It has to do with the way the original site was set up as it was interacting with a SaaS product main domain on the main domain site.com before I acquired it in an asset sale.

Digging into the site, I don't see an obvious way to turn off the sub-domain version without killing the subfolder version. I've tried a few methods.

So I figured the best way would be to make the subdomain version canonical to the subfolder one. Where the canonical structure would point like this automatically:

blog.site.com -> site.com/blog
blog.site.com/post-1 -> site.com/blog/post-1
blog.site.com/category2 -> site.com/blog/category2

To help pass over rankings and link juice, I think this would be the simplest solution. I couldn't find a plugin to do this for me.
Does anybody have any idea on how to do this? Maybe with a PHP file change or something?

Since they're mirrors of each other, whatever change would reflect on both versions, but as long as the subfolder version is the one that is always listed, I think it'll be fine.
Would appreciate any help!
 
Why not do a simple redirect, redirect the subdomain to the sub-folder and wait for the recrawls to happen:

.htaccess version
Code:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^sub.domain.com
RewriteRule ^(.*)$ /subdomains/sub/$1 [L,NC,QSA]

OR are you scared you are going to lose ALL the rankings from the sub-domain? You won't, long term. During the transition some traffic will dip. In fact you might gain in that scenario:

 
Why not do a simple redirect, redirect the subdomain to the sub-folder and wait for the recrawls to happen:

.htaccess version
Code:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^sub.domain.com
RewriteRule ^(.*)$ /subdomains/sub/$1 [L,NC,QSA]

OR are you scared you are going to lose ALL the rankings from the sub-domain? You won't, long term. During the transition some traffic will dip. In fact you might gain in that scenario:

A 301 would work too - I just didn't know how to bulk 301 every page automatically (every new post will need it too). is that what that htaccess code would do?

Was also concerned about infinite loop type issue (both sites are mirrored) so whatever 301 logic I had written on the subdomain would also show up on the sub-folder version. Was worried it might just keep redirecting to itself even when it's on domain.com/blog where it'd just keep re-directing to domain.com/blog

I'm not super versed playing with .htaccess, just been going and playing around with stuff and googling. I've already broken the site 3x already haha, luckily I always backup!

EDIT: I should also note that the admin panel is on the subdomain version - for some reason the admin panel will never work on the subfolder version
 
Yeah the code would do the bulk redirect. You might be better off paying someone to fix it correctly TBH. Less guessing and wasting time.
 
Back