How to Serve a Subdomain as a Subdirectory
Let’s say you’ve gotten a website constructed on a platform that excels at design and it’s to be had at instance.com. But that platform falls quick at running a blog. So you assume to your self, “What if I may use a other running a blog platform and make it to be had at instance.com/weblog?” Most other people would let you know that is going towards how DNS and internet sites are meant to paintings and to use a subdomain as a substitute. But there are advantages to maintaining your content material at the root area that we simply don’t get with subdomains. There’s a method to serve two other platforms at the similar URL. And I’m going to display you the name of the game sauce in order that, via the top of this text, we’ll make weblog.instance.com serve as instance.com/weblog. Why you’d need to do that Because you’re right here, you most likely already know why that is a trail to pursue. But I’d like to be sure you are right here for the main explanation why to do that: search engine marketing. Check out those 14 case research that display certain effects when other people transfer their subdomains over to subdirectories. You need your weblog and your area to proportion search engine marketing price. Putting it on a subdomain would reasonably disconnect the 2. This used to be my explanation why, and wound up merging two platforms, the place the principle area used to be on WordPress and the subdomain used to be on Drupal. But this instructional is platform agnostic — it’ll paintings with on the subject of any platform. That stated, the Cloudflare way we’re protecting on this instructional is incompatible with Shopify until you pay for Cloudflare’s Enterprise plan. That’s as a result of Shopify additionally makes use of Cloudflare and does no longer permit us to proxy the visitors on their loose pricing tier. Step 0 (Preview) Before I leap in, I need to give an explanation for the top stage of what’s going to occur. In quick, we’ll have two web pages: our major one (instance.com) and the subdomain (weblog.instance.com). I exploit “weblog” as an instance, however in my case, I wanted to drop in Drupal with a other form of content material. But a weblog is the standard use case. This way is dependent upon the usage of Cloudflare for DNS and a little further one thing that’ll give you the magic. We’re going to inform Cloudflare that once any person visits instance.com/weblog, it must: intercept that request (as a result of instance.com/weblog doesn’t actually exist), request a other area (weblog.instance.com/weblog) in the back of the scenes, and ship the effects from that remaining step to the customer masked thru instance.com/weblog. Okay, let’s dive into it in additional element! Step 1: Using Cloudflare Again, we’re the usage of Cloudflare for the DNS. Pointing your area’s DNS there is step one to getting began. The explanation why for Cloudflare is that it permits us to create Workers which can be in a position to operating a little bit of code anytime anyone visits positive URLs (known as Routes which we’ll create in step 3). This code will likely be accountable for switching the internet sites in the back of the scenes. Cloudflare has a very good information to getting began. The function is to level your area’s — anyplace it’s registered — to Cloudflare’s nameservers and ensure that Cloudflare is attached to your Cloudflare account. Step 2: Create the Worker This code will likely be accountable for switching the internet sites in…
Like to keep reading?
This article first appeared on css-tricks.com. If you'd like to keep reading, follow the white rabbit.