Codex

Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

User:Vancoder

Many people want WordPress to power their main site but they don't want all of the WordPress files cluttering up their root directory.

No problem. WordPress allows you to tidy the majority of its files into a subdirectory, whilst still powering your main site.

Note: by necessity, your site will break temporarily when carrying out these steps, so you might want to wait for a time of low activity to attempt this.

As of Version 3.5, Multisite users may use all of the functionality listed below. If you are running a version of WordPress older then 3.5, please update before installing a Multisite WordPress install in a subdirectory.

Installing WordPress into a subdirectory

  1. First, install WordPress as described in the detailed instructions on installing WordPress. When you reach the part about uploading the files note that, as we want our core files to be tucked neatly away in their own subdirectory, we will upload the whole wordpress directory itself to the root of our site. Feel free to rename the wordpress directory as you see fit. In our example, we will stick with the default name, wordpress.
  2. Once you have WordPress running in your subdirectory, go to the General panel under Settings. The WordPress Address should already be correctly set to http://your-domain/wordpress. The Site Address will show the same URL, but this is not what we want. Change the Site Address to just http://your-domain. Save your changes. Note that the front-end of your site will now be broken. Don't panic! We're almost there.
  3. Copy (don't move) your index.php file from the wordpress subdirectory into the root of your site. Also move your .htaccess file, if you have one.
  4. Open that copy of index.php in a text editor, and edit the line that says

    require('./wp-blog-header.php');

    so that it says

    require('./wordpress/wp-blog-header.php');
    Obviously, if your subdirectory is called something other than wordpress, use your chosen name instead.
  5. Save the file.
  6. That's it! Note that you'll need to access your admin using your subdirectory name, http://your-domain/wordpress/wp-admin. This is not necessary for the public pages.
  7. Also note that, if using permalinks, your htaccess file should reside within the root of your site, along with the index.php. WordPress will automatically create the file in the right place, if it can.

Moving a Root install to its own directory

The process to relocate the WordPress core files into their own directory is as follows:

  1. Create the new location for the core WordPress files to be stored (we will use /wordpress in our examples).
  2. Go to the General panel under Settings. The Site Address should already be correctly set to http://your-domain. The WordPress Address will show the same URL, but this is not what we want. Change the WordPress Address to http://your-domain/wordpress. Save your changes. Note that your site will now be broken. Don't panic! We're almost there.
  3. Move all of your WordPress files to the wordpress subdirectory.
  4. Copy (don't move) the index.php and .htaccess files from the wordpress directory into the root directory of your site. The .htaccess file is invisible, so you may have to set your FTP client to show hidden files. If you are not using pretty permalinks, then you may not have a .htaccess file.
    • If you are running WordPress on a Windows (IIS) server and are using pretty permalinks, you'll have a web.config rather than a .htaccess file in your WordPress directory. For the index.php file the instructions remain the same, copy (don't move) the index.php file to your root directory. The web.config file, must be treated differently then the .htaccess file so you must move (don't copy) the web.config file to your root directory.
  5. Open your root directory's index.php in a text editor, and edit the line that says

    require('./wp-blog-header.php');

    so that it says

    require('./wordpress/wp-blog-header.php');
    Obviously, if your subdirectory is called something other than wordpress, use your chosen name instead.
  6. Save the file.
  7. That's it! Note that you'll need to access your admin using your subdirectory name, http://your-domain/wordpress/wp-admin. This is not necessary for the public pages.

Expanding a subdirectory installation

If you already have WordPress installed in its own folder (e.g., http://example.com/wordpress), then the steps are as follows:

  1. Go to the General panel under Settings. The WordPress Address should already be correctly set to http://your-domain/wordpress. The Site Address will show the same URL, but this is not what we want. Change the Site Address to just http://your-domain. Save your changes. Note that the front-end of your site will now be broken. Don't panic! We're almost there.
  2. Copy (don't move) the index.php and .htaccess files from the wordpress directory into the root directory of your site (WordPress may already have recreated the .htaccess file for you in the previous step). The .htaccess file is invisible, so you may have to set your FTP client to show hidden files. If you are not using pretty permalinks, then you may not have a .htaccess file.
    • If you are running WordPress on a Windows (IIS) server and are using pretty permalinks, you'll have a web.config rather than a .htaccess file in your WordPress directory. For the index.php file the instructions remain the same, copy (don't move) the index.php file to your root directory. The web.config file, must be treated differently then the .htaccess file so you must move (don't copy) the web.config file to your root directory.
  3. Open your root directory's index.php in a text editor, and edit the line that says

    require('./wp-blog-header.php');

    so that it says

    require('./wordpress/wp-blog-header.php');
    Obviously, if your subdirectory is called something other than wordpress, use your chosen name instead.
  4. Save the file.
  5. That's it! Note that you'll need to access your admin using your subdirectory name, http://your-domain/wordpress/wp-admin. This is not necessary for the public pages.
  6. If you already have content in your site, see when your domain name or URLs change for how to deal with references to the old URL that will remain in the database.