Menu Close

Move WordPress to a subdirectory with Rancher

About one year ago, I wrote about Create wordpress blog with docker and rancher and was a great thing have a blog full dockerized in our rancher infrastructure.

Today, I’ve another challenge: put a wordpress blog to a subdirectory of a domain, keeping the main site separated from the blog in different docker containers, well.. not so easy.

What we should have, is something like:

https://www.example.com -> docker container with our main site
https://www.example.com/blog -> different docker container with only the blog

I spent lots of time for understand the right way to do this, and finally, I got it!

First of all, you have to install the wordpress blog like I explain in my previous article , so don’t think about the subdirectory, install it to a temporary domain and make it working with the basic installation. The only thing that you have to change from the instruction of the article, is that if you use a host volume, you have to put all /var/www/html folder and not only the wp-content.

Now, don’t think to edit htaccess, wp-config and so on, it’s a pain and you’ll don’t arrive to the result.

The thing is simple, enter to the container and move all the wordpress install to a subfolder:

cd /var/www/html/
mkdir blog
mv * blog

Edit the .htaccess as follow:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>

now, go to the wordpress DB and in wp-options table edit these two options:

siteurl: https://www.example.com/blog
home: https://www.example.com/blog

Ok, now you have your blog that work in a subfolder.

How can we put our main site on the root of the domain? Rancher is our friend!

Go to the load balancer, and set it as follow:

 

Now the load balancer will route all traffic for /blog to our blog container, and all other requests to our main site.

PS: Keep in mind that you have to configure http-> https redirect, you can use one of my docker images for this.

Posted in Domotica e Cloud, Linux, News

2 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *