Moving WordPress to a new subdirectory

I know, I am a bit on a techie kick with my posts recently…but I get asked about this stuff from time to time and it is good to have this information documented on my site.

If you are installing a new WordPress website in a subdirectory of an existing website…you might find this helpful when you are ready to make that new site “Live” and operational to the world:

(p.s. If you’ve already installed WP in subdirectory, some steps might be already done automatically).

  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 Screen.
  3. In WordPress address (URL): set the address of your main WordPress core files. Example: http://example.com/wordpress
  4. In Site address (URL): set root directory’s URL. Example: http://example.com
  5. Click Save Changes. (Do not worry about the errors that happen now! Continue reading)
  6. Now move your WordPress core files (from root directory) to the subdirectory.
  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 than the .htaccess file so you must MOVE (DON’T COPY) the web.config file to your root directory.
  8. Open your root directory’s index.php file in a text editor
  9. Change the following and save the file. Change the line that says:
    require( dirname( __FILE__ ) . '/wp-blog-header.php' );
    to the following, using your directory name for the WordPress core files:
    require( dirname( __FILE__ ) . '/wordpress/wp-blog-header.php' );
  10. Login to the new location. It might now be http://example.com/wordpress/wp-admin/
  11. If you have set up Permalinks, go to the Permalinks Screen 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.)

(Step 7 is not really necessary as you already have those files in the new installation on the subdirectory)

(Hopefully modifying the .htaccess file wont be necessary…in my experience just going to the Permalinks screen and hitting save/update does the trick…but just in case)

.htaccess modification

In some cases, some people like to install separate versions in a subdirectory (such as /2010, /2011, /latest and etc..), and want that website (by default) used the latest version, then Install WordPress in a subdirectory, such as /my_subdir and in your root folder’s .htaccess file add the following (just change the words as you need):

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteRule ^(/)?$ my_subdir[L]

Now when users go to your root domain (example.com), it will automatically redirect to the subdirectory you specified.

That should do the trick…one thing to always remember….backup your files and database JUST IN CASE!!! You never know when a glitch may happen in the process so always be safe.

Have a great day!

Scott E

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s