How To Host Your WordPress Blog In A Sub-Folder, Hosted Separately
I had an interesting situation to deal with for a client. His main website was hosted somewhere else on a proprietary system, yet he wanted his WordPress blog to look like it was part of the same website. He wanted his blog to show up in a sub-folder despite the fact that it was hosted somewhere else and using WordPress.
In this video, I’ll show you how we used a proxy script (called a worker route) in Cloudflare to enable us to host his WordPress site separately, but make it look like it was part of his main website.
This same method would be usable in similar situations, such as using Shopify, ClickFunnels, Kajabi or any other such system. If your main domain is routed to any non-WordPress service but you still want your blog on WordPress, this method can make it look like it is all the same website.
For the full post and the code for the script to be used for your Cloudflare Worker, see the full post.
Transcript Of This Video
[00:00:01.09]
So I had an interesting situation come up for a concierge client of mine where he has his main website hosted in one place, but he needed his blog to be on WordPress, which is a different platform, and hosted someplace else. And we didn’t want to use a subdomain on that. And so we came up with a solution, and I wanted to share it with you. Okay, so So typically, when you want to have different sections of your website that are on two different hosts, you would use your DNS in order to do that. You would basically create subdomains, okay? And so you can have your main domain, like your www part, pointing to one place, and you could create a subdomain such as blog. Yourdomain. Com and have it go someplace else. And using DNS to do it with subdomains is incredibly easy. It’s very common. It’s the most typical use for a subdomain, actually, is to be able to point it at different hosts. The thing is, from an SEO perspective, the subdomain is not quite as good. It’s actually looked at as basically a separate website. And generally speaking, for SEO, it’s better to have your blog look like it’s in a folder versus sitting on a completely different subdomain from your main website.
[00:01:28.24]
And so that was the situation that my client was in. He wanted his site, his blog, to be on WordPress because WordPress is purpose-built for that. But he wanted it to be on blog. He basically wanted it to look like it was in a folder on his website, not on a separate subdomain. But yet, he had his main website being hosted by some proprietary provider of a job board, because in this particular client’s case, his main website is a job board, and it’s being done by a company that does this job board, and that’s where the DNS is pointed. So we have his site going over there, and we want his WordPress blog to look like it’s inside of a subfolder Those guys don’t deal with WordPress. So what do we do? And it’s a very similar situation. Let’s say that you had a Shopify store, but you wanted a blog on WordPress, or you had some of your sites sitting over on Kajabi or something like that, but you wanted WordPress to look like it’s in a subfolder and have the blog there. Well, it can be done, and we had to rack our brain about it.
[00:02:43.01]
We did some research. In fact, I even came up or found a company called PressProxy, which is basically a web host, except that their main thing that they do is that they set up what’s called a proxy script so that it’ll make the blog look like it’s showing up in a subfolder, regardless of whatever you might be using for the main website. Now, press proxy is not what we ended up using. I was able to do it myself, and we basically ran his blog through my own hosting, since he’s a client of mine, except that we were able to not have to deal with so much complexity to make it actually work. Now, the secret to doing this is that you need to use Cloudflare as your DNS. So if you’re not using Cloudflare as your DNS provider for your domain, you’re going to need to switch over to Cloudflare in order to use this particular setup. But I use the free version of Cloudflare. I don’t have to pay for it. So it’s easy. If you’re not using Cloudflare, I do recommend that you switch over because Cloudflare has a lot of advantages over using your web host to manage your DNS settings because Cloudflare just has a lot of capabilities capabilities that your typical web host isn’t going to have when you can manage DNS there.
[00:04:05.13]
And this capability that we’re about to utilize is definitely one of them. Okay, so here’s the basics of what we’re going to do. First of all, set up your WordPress site on a subdomain. I know that that’s not where we’re heading with this ultimately, but in order to have it out there, it needs to be on a different host. So you’re going to go ahead and set it up on a subdomain first. And then what we’re going to do is we’re going to use is what’s called a worker script inside of Cloudflare that is going to basically set up a proxy. And what it’s going to do is it’s going to take all of the URLs from the main domain/blog, basically the subdirectory, And behind the scenes, it’s going to map it over to your subdomain. So the subdomain will still be there. That’s how you’re going to get WordPress to work someplace else. But we’re going to use this worker script in order to make it basically look like it’s coming from the folder. And this is all going to be done using what’s called a worker script and a worker route inside of Cloudflare.
[00:05:06.23]
Now, I want to also be clear, this is an actual piece of code. This is some programming. And so obviously, I’m not going to sit here in a video and I’m not going to show you script because that would be really annoying. What you’re going to do is if you’re on YouTube right now, go to the video description, click on the link that goes over to my blog, and the script will be there. You can copy and paste paste it, and you can stick it into your Cloudflare account. The script will be there for you. If you’re already on my blog, well, just go below and the script will be there. With that being said, let me quickly show you where to find this stuff inside of Cloudflare. The first thing is when you’re inside your Cloudflare account, you’re going to want to go down to the section for Workers and Pages, and we’re going to go ahead and create the script. Now, I’m not going to do it here on screen because you can actually see that it already exists in this particular account. Because that’s what I did. But what you would do is go to Create, and you’re going to go to Create a worker, and then you’re going to have this script here.
[00:06:08.29]
This is where you’re actually going to write the script that’s actually going to do the routing for you. Now, the Keep in mind here, again, the script is below, or if you’re on YouTube right now, just go below in the description and click on the link, go over to my blog, and I’ll give you the script that you can copy and paste into this because it definitely takes a little bit of to figure out how to write it. So go and do that. And as far as your title, I just called it blog proxy, but you can call it whatever the heck you want. It really doesn’t matter because all you’re really going to need this name for is to be able to reference it later. So that’s where it actually exists. Under your main account, and you’ll just create the worker script. And then what you need to do is you need to go over to your actual domain, and we need to set up what’s called a worker route, where we’re basically going to set it up and say, well, apply this particular script on traffic that matches certain criteria. In this particular case, because this is one of my clients with Proactuary, is that we’re taking all of his traffic that goes to his subfolder of /resources, and we’re remapping it to go over to his subdomain.
[00:07:20.25]
It’s just that the traffic on people on his website are not really going to know that they’re accessing something on a subdomain because it’s It’s going to look like it’s coming from the folder. All right, so let’s go over to his site and I’ll show you the worker route. Now, again, when you go to the actual settings for the domain, you go to worker route, and you would have to add a route, which you would then name it whatever you want, and you would choose the worker that you just created. In my case, it was blog proxy, and that’s basically all you would really need to do there. Now, let me show you the settings here on his. We made it to where the route was, the directory, and then we put the little asterisk at the end of it basically as a wild card. So it would intercept his domain/resources, and then anything that comes after that. And we would then route that to the worker script that we just created. And that’s basically how that works. And then we would deploy that setup. And then what will then happen is that it will take all that traffic to that folder, and it will route it basically over to his subdomain, but with the exact same URL structure that was in use.
[00:08:36.28]
You need to have the permalink set up over there to where it will take that, and it will do what it’s supposed to do. But this worker script is what’s actually going to take place to route the traffic. It’s basically a proxy to route the traffic from the folder to the subdomain. Now, once that worker is deployed, it should start to take effect pretty quick. One thing I’ve noticed is that DNS tends to be pretty fast with Cloudflare. Changes are pretty quick. Now, one very, very important point here is that the Cloudflare proxy needs to be turned on on your account. So if you’re just using Cloudflare as DNS and all the little cloud icons are off, you’re going to need to turn the proxy on for this to work. Because by doing that, it puts Cloudflare in the middle and it gives that script a chance to execute. So what you’re going to want to do is you’re going to want to go to the non-WW version and the WWW version of your domain, find those sections on your DNS, and you want to activate the little Cloudflare icon. Make sure you turn it orange, and that will turn on the cloudflare their proxy, and that will allow this script to execute.
[00:09:48.10]
If you don’t have that little thing turned on, it’s not going to run. It’s just going to go pass right straight through to your server directly, and the thing won’t work. Now, one other thing that is definitely also important is is that when people arrive on your WordPress blog, you want to make sure they can continue to click around the blog and not have the URLs change on them. And the thing is, with the way that the WordPress database works, all of the internal links are basically defined by whatever site URL you have inside of your WordPress settings. And so what could happen is that if you have WordPress sitting on a subdomain, but you have this little worker script sending traffic to looking like it’s from a folder, if the person clicks on something else on your blog, they’re going to suddenly flip over to the subdomain again. And all the internal links on your blog are going to look like they’re from a subdomain. So what you need to do to get around that is you need to change basically the URL inside the database of WordPress and make it so that it’s using the folder structure and not the subdomain structure.
[00:10:56.26]
That way, when navigation menu links, and internal links work in WordPress, it will use the proper folder structure, not the subdomain. If you want to change that, you probably could just go ahead and change it directly in the WordPress settings in the option screen. It should work because now your Cloudflare worker script should be running. But worst case scenario, just open up your database directly. You can pop into your WPoptions table and you can change the site URL there if you absolutely have to. But make sure you do that, otherwise your internal links are not going to be working the way that you intend. And lastly, just to show you the effect that all this has, this is the client’s actual main homepage. You can see that it’s basically a job board, proprietary job board. And I don’t host this. I got nothing to do with this part of it. But if we go over to this, this is his actual blog. This isn’t sitting inside of WordPress. You can see we can click around here. But note the folder. It’s his domain/resources, and it’s clicking around and doing everything that it’s supposed to do, even though this is a WordPress blog and it’s hosted on a completely different host, but it just looks like it’s coming from a folder.
[00:12:12.11]
And that’s basically it. And when people click back and forth, they can pop between the two parts of the website, the proprietary job board, and then the part that’s sitting over inside a WordPress. And that’s how it actually works. It looks like it’s all the same site, but it’s actually split among two different hosts and two different platforms. Okay, so was that super nerdy or what? Well, at the end of the day, it’s not that difficult to execute. I think you could probably figure it out with the help of this video and the fact that I’ve given you the code. But that being said, it definitely can be handy in situations where you have different parts of your site hosted in different places, but you don’t want it to look like they’re hosted in different places. You can actually do that. In this case, I’ve got his blog sitting on WordPress, hosted over on in my xCloud, and it works great, even though his job board and his main website is someplace completely different, and I don’t even manage that part of it. So it works out really nicely. So anyway, if you’re not able to execute this on your own, but you really need it to be set up, I’m happy to help you out.
[00:13:17.18]
I’ve already given you the code and everything, but if you just want me to jump in there and do it for you, head on over to blogmarketingacademy. Com, click on Services, and get in touch with me. As long as you have at least one credit on your account, I will drop in there. We’ll set it up on your Cloudflare account, and we will get this thing working for you, okay? It’s not too bad. I can definitely get it done for you pretty quick, and I’m happy to alleviate the headache for you. All right? Talk to you soon.