A common problem we have often faced here at KIJO is how to manage our WordPress settings across multiple server environments. Having to change the settings for each environment or having different versions for each environment is not practical. Popular setups often utilise 3 or more servers for different stages of the development process, these are development, staging and production.
Below is our solution for having one .htaccess that works across all your server environments seamlessly.
One .htaccess to rule them all
The code snippet below works by creating a variable called ‘rebase’ (which could be changed to any variable name). The variable is set according to the URL your are visiting from. Here is how it would work for your different environments.
Firstly if its your production environment then nothing is changed as you won’t be operating out of a subfolder.
Next it checks to see if your operating in your development environment by looking for the localhost URL. If this is true then it will add the subfolder ‘kijo/’ and this can be changed to whatever subfolder your development installation resides in.
Lastly it looks to see if your using your staging environment and checks if the URL is ‘staging’kijo.co’. If this is true then it again adds a subfolder of ‘kijo/’. Delete this if necessary if your staging installation doesn’t reside in a subfolder.
We originally discovered this snippet here and its also available on our Github.
Keep an eye out for our solution on how to manage wp-config settings across multiple WordPress installations in a future blog post.