Can you have a blog in a subdirectory hosted on a different server?

I am interested in having a blog on my site which will be in a subdirectory of the main wordpress homepage

e.g. website.com/blog

however, I am interested to know if there is a way to host the blog on a separate server - primarily because I don't want to overload the server for the rest of the site if there is a lot of traffic going to the blog. I am keen on the idea of it being a subdirectory though.

Anyway - just thought there would be someone smarter than me who might have a bright idea :)

Topic blog shared-hosting server Wordpress

Category Web


A reverse proxy could work, such as varnish or nginx. Using varnish as an example:

backend blog {
   .host = "blog-server-ip";
}

backend default {
   .host = "current-domain-ip";
}

sub vcl_recv {
   if (req.rul ~ "^/blog/") {
      req.backend = blog;
   }
}

A better way to to do this is to instead of a subdirectory, use a subdomain like blog.website.com. The reason for this is that a DNS record can be made to the other server for the subdomain, which is not possible with subdirectories.

A subdirectory is possible, but you would have to use frames, a .htaccess redirect or another way which is totally not stable in a production environment.

If you want to use a subdirectory like example.com/blog, the best way (and it's not a good way...) is to use an .htaccess file. You can make a redirect like this: Redirect 301 <server IP> where server IP stands for the IP address of the server you want to host your blog on. Note that the user will see the IP address in the address bar which is not recommendable.

Therefore, you might also want to give frames a try. Use iFrames, frames are outdated and no-one will recommend to use them. Note that iFrames or frames aren't a good solution either, but if you really want to use a subdirectory this is what you'll have to do... create an index file (e.g. website.com/blog), and place <iframe src="<server IP>"></iframe> there.

Note that also this is no good solution and I really recommend using a subdomain.

If you want to use a subdomain like blog.website.com, go to a place where you can manage your domain's DNS and add a an A record which points to the IP of the server you are going to host your blog on.

Edit: this is off-topic, but worth mentioning: if you don't want an overload on your server, instead of having multiple servers, you can set up cluster hosting. This is a very handy technique, especially for websites that have many traffic. The concept is to spread the load of hosting across multiple servers. Here's the Wikipedia article about clustered hosting - I recommend reading it. There are multiple hosting providers that offer cluster hosting. Unfortunately I only know Dutch hosting providers that offer clustered hosting, so I can't recommend one. The cheapest I know in The Netherlands is about €100,- per year, so clustered hosting is quite affordable.

Good luck!


Does it have to be website.com/blog?

A faster solution and less complex would be to just host the blog as blog.website.com

For website.com/blog, your best solution is to employ URL Redirects..

see:

https://serverfault.com/questions/567476/permanently-redirect-subfolder-blog-to-subdomain-on-another-server

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.