Installing Wordpress in a Subdirectory

There are two reasons I like to install Wordpress in its own folder, rather than the  root. First, I like to keep my root folder uncluttered. I don’t like a bunch of Wordpress files that I’ll never be messing with getting in my way.  That’s just a matter of personal preference though. The second reason is for security. To prevent automated site scans from easily finding my Wordpress files, I simply place them in a separate directory. So… here’s how you do it. It’s actually quite simple.

1. Install Wordpress in a subdirectory

Just follow the instructions I gave in my post Installing Wordpress Manually. Make sure you create a new directory and upload the Wordpress installation files there (that’s step three in the post I just mentioned).

2. Edit the index.php file

Once Wordpress is installed, download the index.php from the directory where you uploaded Wordpress. You’ll need to open it up and make one small change. Find this piece of code:

/** Loads the WordPress Environment and Template */<br>
require('./wp-blog-header.php');

All you need to do is tell it how to find wp-blog-header.php in its new subdirectory. For example, here’s what the code would look like if I installed Wordpress in a directory called example.

/** Loads the WordPress Environment and Template */<br>
require('./example/wp-blog-header.php');

Notice how I added /example just before /wp-blog-header.php. So just add the name of your directory in place of example and that’s all the code editing you have to do.

3. Upload the new index.php file

Now that you’ve made the necessary change to your index.php file, it’s time to upload it to your root directory. Make sure you delete the old index.php file in your Wordpress directory.

4. Tell Wordpress what you did

Finally, you need to let Wordpress know about the change. First, log into Wordpress. The login page will still be at the old URL (for example http://alexmansfield.com/example/wp-login.php not http://alexmansfield.com/wp-login.php). Go to Settings>General and change the Blog Address field (for example, from http://alexmansfield.com/example/ to http://alexmansfield.com/). Save your changes and that should do it!

If you have any questions, please ask them in the comments section below.

Category: Wordpress | Tags: Security, Wordpress Follow comments with RSS 2.0

6 Responses to “Installing Wordpress in a Subdirectory”

  1. Carlos Salazar | March 20, 2010 at 9:22 pm

    I installed wordpress in a subdirectory and this is about third article I read stating the same steps. But I still get the directory index displaying after I log into the admin panel. In addition, I go to my directory I installed wordpress and I get the directory index as well. No page is generated. Any help would greatly be appreciated. Thank you so much.

  2. alexmansfield | March 20, 2010 at 9:30 pm

    There could be a few different things causing this. When you see the directory index, is there an index.php file listed? Also, do you know what operating system your server is running?

  3. SFGolfer | April 28, 2010 at 3:09 pm

    Just one small problem.

    The name of your subdirectory appears in the page’s source code. Plus, if you link to an image, the img src will also include the subdirectory name.

    I thought this was to “hide” the location of the wordpress files? Any ideas?

  4. alexmansfield | April 28, 2010 at 3:36 pm

    That’s true, SFGolfer. The purpose of using a subdirectory isn’t really to hide Wordpress from prying eyes. Rather, it moves the Wordpress files away from the default location so that scripts that look for them in the usual spot don’t see them. The original posts wasn’t clear about that, so thanks for pointing it out. I’ve edited the beginning of the post to reflect that issue.

  5. Jennifer | June 18, 2010 at 12:05 pm

    I’m having the same problem as @Carlos above. Did you have a solution for him?

  6. alexmansfield | June 18, 2010 at 12:11 pm

    Like I mentioned to Carlos, there could be a number of different causes. It could be a problem with the file permissions not allowing Wordpress to run the scripts necessary to generate the page. If you’d like, you can contact me through my contact form with a link to your site and I can try to help you figure it out.

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>