How to: Install WordPress in a sub folder

Wordpress folder
Are you hosting WordPress yourself?

A great new feature is that you’re now able to keep the WordPress core folders and files in a separate sub folder.

The core files are all the WordPress installation files which you never touch or alter. All the other files which you upload, plug-ins, themes and configuration files are kept apart. This helps greatly to reduce the “unclean” mix of files of your installation. And, reduces the risk of deleting files which you should stay away from (the core WordPress installation files).

Another very helpful aspect of this feature is the ability to soft launch / beta test a new WordPress blog in a less prominent way (e.g. yoururl.com/testblog ) and than move it to the main location with the simple procedure below.

To reiterate: You can apply this in two ways, either by starting in a sub directory and than move the blog to the main URL/directory or you did set up your blog under the main URL/directory and want to move the core WordPress files into its own sub directory.

Below you’ll find the complete description from the WordPress codex about giving WordPress its own directory:

  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 Blog 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 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.
  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('./wp-blog-header.php');
    to the following, using your directory name for the WordPress core files:
    require('./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 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.)

Please feel free to ask questions in the comments section below. I’ll help you to get this set up and working. Thanks!

31 thoughts on “How to: Install WordPress in a sub folder

  1. Thank you very much for your tutorial. helped me a lot. I tested it first on a local installation of wordpress, and works perfect. I will be able now to do it on my website as I am intending to merge my portfolio and existing blog in wordpress. the portfolio will be pages.

  2. I did follow your steps and installed WP into a subdirectory for multilingual website: /pt/ & /en/ but it doesn’t work properly for the second language and twice the folder into the url like this ../pt/pt/…
    I don’t know what’s wrong… could you help? thks anyway

    1. Hi “Imobiliária João Pessoa”,

      My instructions help you to move most of the WP core files into a sub directory but it’ll be a little harder to make this work with multiple WP installations. Have you thought about using just one WP installation and than try to utilize a multi-lingual plugin?

      Cheers,
      Marco

  3. Hi Marco,

    Hi have been reading you blog and I have to say that I found it very interesting. I have a question regarding a similar scenario.

    I have a static website installed in the root folder: http://www.atwebpresence.com

    I have recently enabled a wordpress blog that I have decided of installing under the a sub-folder of the root called blog: http://www.atwebpresence.com/blog/

    My question is about the the RSS feed url. Normally, this is being generated by wordpress as follow: http://www.atwebpresence.com/feed/

    The problem is that a conflict of the .htaccess file between the root and the wordpress folder is preventing preventing this url from being built properly. I have found out that the real RSS feed url should be this one instead:
    http://www.atwebpresence.com/blog/feed/

    I was wondering if you could give me a hand with this.

    Best regards,
    Antonio

    1. Hey Antonio,

      Alright, let’s see how we can help you. I just took a brief look at your site and it seems to category/tag feeds seem to use the correct URL. Let’s make sure that WP is set up correctly before we dive into fixing things. Could you list your config of WP?

      What is you “home/blog URL” (you’ll find this under “Settings/General”) and what does your permalink structure look like (“Settings/Permalinks”)?

      Cheers,
      Marco

  4. Thanks Marco,
    you’re right it works great for the core files into a sub directory, but still looking for ‘multi’multilingual install… I’ve tried WPML plugin, but it’s not the best for all theme, widgets and plugins tanslations…
    I let you know if I find out, it might help some visitors of your great site.
    Cheers

  5. Hi Marco
    I have a strange problem that has happened both times (two sites) when I have moved the site from the subdirectory to the root to go live. All instructions followed exactly. And the site works in the root. Both sites have a few static pages and a blog page with comments which worked fine when in the subfolder. However, when I move the site to the root, blog comment functionality stops working – I can no longer see the reply box and the links on the right: recent posts, recent comments, archives etc look like hyperlinks but do not click. I have been searching for hours for a solution but can’t find one. I am fairly new to WordPress so perhaps I am doing something wrong. Any help much appreciated.

  6. Angie,
    Do you have plugin activated which could interfere? Did you test with all plugins disabled (and maybe switching to the twentyeleven theme)?

    That would be my first step in trouble shooting your issue. Let me know if this is changing anything, or, if you find out what the problem was. I’m happy to help fi you give me a little more details after switching off all plugins.

    Cheers!

  7. Hi, thanks for dealing with this particular topic. I think I’m having a little different issue with my WordPress. I put it in a /wordpress subfolder to begin with during install, and I can resolve the new URL to get to the main blog page, and I can go directly to each of the blogs using their respective URLs with category slugs, etc.

    But I can’t seem to get the blogs seen or indexed by search engines. I have a theory that having a second sitemap.xml (and lots of other files for the blog) beneath the main site url in a subdirectory may be making it hard to crawl and index. Furthermore, I have an “index.php” already in my root directory and it’s my homepage for my website, so I don’t feel like overwriting that with one from WordPress. Does that make any sense? Could it be that my problem is that I have two full-blown websites, one under the other?

    Thanks much in advance for any advice.

    1. Hi Rich,

      Here are a few thoughts about solving your issue.

      Search engines will only look for the sitemap.xml in the “main folder”/htdocs root of your site (or, you’d need to link to it in your robots.txt file). But there is only 1 (!) sitemap.xml to begin with. The good news is that you can link to as many sub-sitemaps from inside the main sitemap as you see fit.

      So, you need to make sure to have either no sitemap at all (let the search bot figure it out by itself), or, you need to integrate the WordPress sitemap into the main sitemap. You can accomplish this by simply placing a link to the (sub-)sitemap at the bottom of the main one (sitemap conform).

      Another solution is to manually add all the pages of the main site into the WP sitemap and change the location (in WP plugin settings) to the main/root folder of your site. This way you end up with just one sitemap, too.

      Let me know if this helps you to get your WordPress site indexed.

      Cheers!
      -Marco

  8. Hi

    Hopefully you can point me in the right direction. I have a site http://www.refinishingtouch.co.uk that structures much of its content under subfolders e.g. http://www.refinishingtouch.co.uk/bathrooms/index.php.

    It also has a wordpress blog installed under /blog/ and while I can get to the blog correctly at http://www.refinishingtouch.co.uk/blog, the permalinks to the individual posts are incorrect as they do not have the /blog/ folder e.g. http://www.refinishingtouch.co.uk/?p=22 (which causes the home page to be displayed) instead of http://www.refinishingtouch.co.uk/blog/?p=22.

    WordPress URL is http://www.refinishingtouch.co.uk/blog
    Site URL is http://www.refinishingtouch.co.uk

    I’ve tried with various configurations of .htaccess in web root folder as well as no .htaccess – any idea what I am doing wrong?

    Also if I try changing the permalink to anything other than default I get the “This is somewhat embarrassing, isn’t it? It seems we can’t find what you’re looking for. Perhaps searching, or one of the links below, can help.” error page. The instant I switch back to the default permalink setting the blog front page is restored with the posts listed.

    TIA

    Stuart

    1. Hi Stuart,

      I hope my reply is still helpful for you. Not sure why I missed your comment.

      You should make your WP and Site URL point to …/blog AND you should make sure that your “Permalinks” also include the /blog/ in it (e.g. /blog/%postname%/ ). I’m pretty sure that if everything works fine on the front page (of your blog) that it’s not set up right in the permalinks setting. That would explain your issue above. Let me know if you got it sorted out. Thanks!

  9. Hi Marco,

    I’m trying to run a wordpress site next to my normal site which does not use wordpress. I put all the files in a subfolder, however I cannot put the index.php and htaccess file in te root because they are being used by my original site. What can I do?

    Thanks!

    1. Hi Marijin,
      Just put your (WP) index.php in the sub-folder and change the WordPress (and Site) URLs to include the subfolder’s name. And, make sure to add the subfolder’s name in the permalink setting, too (see my reply to Stuart for more details). Does that work for you than? Cheers!
      -Marco

  10. Thanks for the tute, very helpful!

    I have one very pressing question… the link mysite.com/subfolder now leads to a 404 page, which I’d like to redirect to my home-page, is this a smart redirect to place in htaccess? Please advise!

    1. @AUti: Yes, you could add an .htaccess file in there to redirect visitors to the home page. Probably something along the lines of:
      Redirect 301 ^/subfolder/?$ http://mysite.com/

      I’ve not tested this myself. Please let me know if this works for you. Thanks!!

  11. Excellent, very clear directions, I’d been pulling my hair out for an hour but simply applying #9 sorted me out perfectly.

    Fantastic design! The excellent choice of font and large font size makes reading technical instructions like this very clear.

  12. Hi,

    I’m very fresh to the web world and WP is proving to be very helpful.

    I would like to install WP in a sub folder in my public html folder to test another WP theme. I have made the folder but cannot find how to install WP to then install and edit the theme. What am I missing?

    http://www.theflyergiants.co.uk

    Thanks
    aks

    1. Hi Aks,

      It sounds like you have WP already installed in your “main” html folder. Is that right? If you want to install a 2nd WP installation in a subfolder and you only want to get to it by appending the subfolder’s name to your domain then you do not need to follow the instructions provided above.

      Simply upload the WP core files into the subfolder and go to that URL and follow the “normal” WP setup process. Just make sure to always enter in the URL of your blog WITH the subfolder’s name.

      If you install it the way it’s described above then you’d end up with a WP installation that’ll “show up” on your (root) URL (w/o the subfolder’s name). From your question above it sounds like that’s not want you want.

      Please let me know if this helps you to get the installation working. I’m happy to help if you run into any other problems.

      Cheers!
      -Marco

Leave a Reply

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