Running WordPress in different directory

By 1st August 2017September 15th, 2020No Comments

MageStack allows you to run WordPress in a manner of different ways, if you simply want to run your blog from a directory called /blog - see running WordPress in a subdirectory. But if you want to run a more complex WordPress deployment, where the URL differs from the directory structure itself, then the follow guide applies.

MageStack uses Nginx as the web server, so you just need to add the following rewrite rules to your respective domain's general rules.


Running a blog from /blog where the directory is /wp/wordpress

Edit ___general/,

set $wordpress_dir '/wp/wordpress';

location ~* /blog(/|$) {
  location ~* \.(php)$ {
    rewrite ^/blog/(.*)$ $wordpress_dir/$1 break;
    include fastcgi_params;
  rewrite ^/blog/(.*)$ $wordpress_dir/$1 break;
  try_files $uri $uri/ $wordpress_dir/index.php;

Adjust /blog/ to reflect the web URI and $wordpress_dir to suit the path of your WordPress installation (relative to the document root)