Giving WordPress Its Own Directory

Giving WordPress Its Own Directory

Many people want WordPress to power their site’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 blog exist in the site root.

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

Moving a Root install to its own directory

The process to move WordPress into its 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). (On linux, use mkdir wordpress from your www directory. You’ll probably want to use “chown apache:apache” on the wordpress directory you created.)
  2. Go to the General panel.
  3. In the box for WordPress address (URL): change the address to the new location of your main WordPress core files. Example: http://example.com/wordpress
  4. In the box for Site address (URL): change the address to the root directory’s URL. Example: http://example.com
  5. Click Save Changes. (Do not worry about the error message and do not try to see your blog at this point! You will probably get a message about file not found.)
  6. Move your WordPress core files to the new location (WordPress address).
  7. Copy (NOT MOVE!) the index.php and .htaccess files from the WordPress directory into the root directory of your site (Blog address). 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.
  1. Open your root directory’s index.php file in a text editor
  2. Change the following and save the file. Change the line that says:
    require(‘./wp-blog-header.php’);
    to the following, using your directory name for the WordPress core files:
    require(‘./wordpress/wp-blog-header.php’);
  3. Login to the new location. It might now be http://example.com/wordpress/wp-admin/
  4. If you have set up Permalinks, go to the Permalinks panel and update your Permalink structure. WordPress will automatically update your .htaccess file if it has the appropriate file permissions. If WordPress can’t write to your .htaccess file, it will display the new rewrite rules to you, which you should manually copy into your .htaccess file (in the same directory as the main index.php file.)

Using a pre-existing subdirectory install

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.
  2. In the box for Site address (URL): change the address to the root directory’s URL. Example: http://example.com
  3. Click Save Changes. (Do not worry about the error message and do not try to see your blog at this point! You will probably get a message about file not found.)
  4. Copy (NOT MOVE!) the index.php and .htaccess files from the WordPress (wordpress in our example) directory into the root directory of your site—the latter is probably named something like www or public_html. 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.
  5. Edit your root directory’s index.php.
    1. Open your root directory’s index.php file in a text editor
    2. Change the line that says:
      require(‘./wp-blog-header.php’);
      to the following, using your directory name for the WordPress core files:
      require(‘./wordpress/wp-blog-header.php’);
    3. Save the file.
  6. Login to your site (if you aren’t still already). The URL should still be http://example.com/wordpress/wp-admin/
  7. If you have set up Permalinks, go to the Permalinks panel and update your Permalink structure. WordPress will automatically update your .htaccess file if it has the appropriate file permissions. If WordPress can’t write to your .htaccess file, it will display the new rewrite rules to you, which you should manually copy into your .htaccess file (in the same directory as the main index.php file.)

Since the site is not working for some of these steps, it is best to make this change at a time of low activity, e.g., the middle of the night.

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.

admin

My name is Serge and I’m a creative geek. I truly love web and I enjoy using its great potential.

View my other posts

6 Comments on “Giving WordPress Its Own Directory”

  1. asd says:

    asdasdssssssssssssssss

    1. Phat says:

      Replying to your comment

      1. lalala says:

        Another comment level

        1. koekman says:

          third level comment

  2. lalalala says:

    Would there be a way to add images to comments?

  3. John says:

    Come to get the top cigaratte here JohnDBlend

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.