Displaying WordPress in a different directory

Overview

WordPress is most often installed in the directory you wish to run the site in. For example:

  • example.com
  • example.com/blog

In these examples, visiting the URL will load the WordPress site that's installed in that directory.

You also have the option to install in a different directory, but have it display from another directory. WordPress describes this in their Giving WordPress Its Own Directory article:

Many people want WordPress to power their website’s root (e.g. http://example.com) but they don’t want all of the WordPress files cluttering up their root directory. WordPress allows you to install it into a subdirectory, but have your website served from the website root.

This article explains how to display WordPress from either the root director or subdirectory when it's been installed somewhere else.

The steps below show how to do this via SSH, but you would create the subdirectory and move the files the same way in an FTP client.

Displaying WordPress in a subdirectory if it's installed in the root directory

This example assumes you've already installed WordPress into example.com, but want it to display at example.com/blog.

  1. Log into your site via FTP or SSH.
  2. Navigate into your website's directory.
    [server]$ cd ~/example.com
  3. Create the subdirectory.

    This example creates a subdirectory named blog.

    [server]$ mkdir blog
  4. Move all of the files in the root directory (example.com) into the subdirectory (example.com/blog).
    [server]$ mv .htaccess license.txt readme.html *.php blog
    [server]$ mv wp-* blog
  5. Create an .htaccess file via FTP or SSH in the root directory (example.com). Add the following contents to the file.

    You only need to update the highlighted text which is your domain name and the subdirectory you created.

    <IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^(www.)?example.com$
    RewriteCond %{REQUEST_URI} !^/blog/
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /blog/$1
    RewriteCond %{HTTP_HOST} ^(www.)?example.com$
    RewriteRule ^(/)?$ blog/index.php [L] 
    </IfModule>

If you visit example.com/blog now, you will see your WordPress site.

Displaying WordPress in the root directory if it's installed in a subdirectory

These steps are the opposite of above. They assume you've installed WordPress in a subdirectory at example.com/blog, but want it to display when visiting example.com.

  1. Log into your site via FTP or SSH.
  2. Navigate into your website's subdirectory.
    [server]$ cd ~/example.com/blog
  3. Copy the index.php and .htaccess files into the root directory. 
    [server]$ cp .htaccess index.php ..
  4. Navigate into your root directory.
    [server]$ cd ..
  5. Edit the index.php file via FTP or SSH. Add the subdirectory name just before /wp-blog-header.php. For example:

    You only need to update the highlighted text which is the subdirectory you created.

    /** Loads the WordPress Environment and Template */
    require __DIR__ . '/blog/wp-blog-header.php';
    

If you visit example.com now, you will see your WordPress site.

Did this article answer your questions?

Article last updated PST.

Still not finding what you're looking for?