Mobile app version of vmapp.org
Login or Join
LarsenBagley505

: How to implement WordPress in a subdirectory, hosted on a different server? I am working with a client who already has a custom e-commerce website set up at their own domain e.g. example.com

@LarsenBagley505

Posted in: #Redirects #Server #Subdirectory #Subdomain #Wordpress

I am working with a client who already has a custom e-commerce website set up at their own domain e.g. example.com

We want to host their WordPress blog at a subdirectory of their domain e.g. example.com/blog
Due to security issues we cannot host WordPress on the same server as the rest of their site.

We have set up a separate server which will host the WordPress blog, and given it a temporary subdomain URL.

How do we make it so that example.com/blog will serve the Wordpress site from our server? We don't want a redirect, we want it to appear as if all of the blog is hosted within the '/blog' subdirectory. What URLs do we put in the WordPress database? How should they be redirecting their subdirectory?

I know people recommend using a subdomain (this is what we currently have), but the client has specifically requested using a subdirectory for better SEO performance.

10.02% popularity Vote Up Vote Down


Login to follow query

More posts by @LarsenBagley505

2 Comments

Sorted by latest first Latest Oldest Best

 

@Margaret670

Your server has an IP address, so you can just grab that and then create a subdomain wherever the DNS for the domain is hosted. So say you want to create blog.domain.com, you can point that to your Servers IP address.

10% popularity Vote Up Vote Down


 

@XinRu657

The subdomain is certainly the easiest option since you are wanting to host the site on another server. The reason for this is that a hostname can only ever resolve to a single location. If you are worried about SEO from the changed URLs, you could perhaps consider a redirect to the subdomain instead.

However, since you are specifically looking to avoid the subdomain, the rest of this answer will focus on how to do that.

If you want /blog/ to be served from a different server, then you would need to create a reverse proxy. Depending on your level of access to the current web server, the best option would be to create a reverse proxy. The following instructions may require some skill with server changes to implement and troubleshoot.

Using Apache

Assuming that you are using Apache, you could add in a rule like this:

ProxyPass /blog/ example.com/blog ProxyPassReverse /blog/ example.com/blog

You could place this in your VirtualHost entry, or somewhere in your httpd.conf. This assumes that you have mod_proxy installed, and it will require an Apache restart.

If you are using cPanel, which is popular, you can look here for locations to place a file with a name ending in .conf: documentation.cpanel.net/display/EA/Modify+Virtualhost+Containers+With+Include+Files
If you are using cPanel, mod_proxy should be included, so you shouldn't have to worry with that, but you will need to /scripts/rebuildhttpdconf and then restart Apache.

This would allow you to make a connection to another location to grab the actual blog pages to serve through your current server.

The problem with WordPress, like many CMS, is that it is very picky about the URL you use to access it. That means that if you were to connect to a subdomain, if the siteurl didn't match, WordPress would serve a 404. Also, WordPress will often output redirects with the siteurl in it. Therefore, you would likely need to make the server think you are connecting to the same URL, even though you are connecting to a remote server. The tricky part is is that you would also need root access to be able to modify your server's hosts file. On a Linux server, you would find that at /etc/hosts/, and you could add a line like this:

123.123.123.123 example.com


Where 123.123.123.123 would be the IP of the server where you would be hosting the blog. Of course, this will only work if nothing else on that server is expecting to connect to example.com.

Using Nginx

If you're using Nginx, which is a bit less common, you could do this a little easier:

upstream blogbackend {
server 123.123.123.123:80;
}

location /blog {
proxy_pass blogbackend; }


Because Nginx allows you to specify an IP for the backend, you shouldn't have to play with the hosts file.

Siteurl

In both cases, the remote server with the blog on it should be configured to serve content for example.com/blog, and that wold be the option_value for both siteurl and home in the $prefixoptions table. If that's the original URL, then you shouldn't have to change it. If you do have to make changes, be prepared to check any hard-coded URLs, such as uploaded images, etc.

Conclusion

This solution is a bit messy, and there's a lot that can go wrong. However, it's still probably cleaner than the next alternative, where you have /blog/ serve content through a PHP proxy, perhaps using curl. This is the reason why the standard approach would be to simply use a subdomain.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme