This week, we are pleased to feature a guest blog post from Josh Vickery, VP of Engineering for SquareFoot. We recently completed a WordPress build for SquareFoot. Josh was able to create a workaround allowing us to install their blog inside their root directory, squarefoot.com – and was kind enough to share with us the details!


Why?

There is much debate on the merits of hosting your blog at https://blog.examplecompany.com or https://examplecompany.com/blog.

It’s worth noting that WPEngine does not recommend this practiceSome people on the internet suggest there is no benefit to doing so. Others suggest otherwise.

For those that want to host at https://site.com/blog and do it with a managed WordPress hosting provider like WPEngine, this article is for you.

(Note, WPEngine will automatically block your reverse proxy, so you will need to contact customer support and ask them to whitelist its IP address in their firewall. I found this to be a painless process thanks to the friendly support staff at WPEngine.)

How?

The trick to getting the blog to look like it’s living on the main site (but actually living elsewhere) is to use a reverse proxy.

HAProxy is a powerful reverse proxy, though its configuration has a bit of a learning curve compared to Nginx or Apache.

We use HAProxy internally because it works well with AWS Elastic Load Balancers, which frequently change their IP address. Learn more

HAProxy config

You’ll need to use SSL, as all WPEngine installs redirect to SSL.

Of note is that HAProxy expects your certificate chain and your private key to be combined into one file

These are the pattern matching lines that we’ll use to determine which traffic is forwarded to WPEngine

This directs /blog*, /leasopedia*, /glossary* and /wp-* to WPEngine.

You can replace these with your own blog and page paths configured in wordpress.

This line also directs /?s= and /?p= to wordpress using the combined root and blog_search and blog_preview lines.

These are necessary to making searching and page previews work in WordPress.

Everything that doesn’t match one of the above patterns will go to the main site.

Directives in the frontend that resolve to this backed will route to the blog.

Directives in the frontend that resolve to this backed will route to your main site.

See it live

I hope you found this useful — and check out the results!