RACHEL McCOLLIN

Fiction and Technical Writer

Moving WordPress from a subdirectory to the root directory – in five minutes!

There are a few reasons why it makes sense to install WordPress in a site’s subdirectory rather than the root directory, particularly during a site’s development:

  • It’s slightly more secure
  • It means that you can build a new WordPress site on a domain that already has a static site running, without disturbing the existing site
  • If there isn’t an existing site, you can put up a holding page in the root directory while the site’s under development.

But obviously when it comes to launching the site, you’ll want it to be accessible from the root directory. The question is – how do you move WordPress from a subdirectory to the root? The obvious answer is to physically move WordPress, the database etc. etc. as you would when moving from one domain to another. But there is a much simpler way to do it, that only involves moving a couple of files and making some straightforward edits. It takes no more than five minutes.

1. Back everything up

Before you start, it’s always a good idea to make a backup of your theme files, plugin files, uploads and the database itself. There are instructions on how to do this in the WordPress codex.

2. Copy just two files

Using FTP or CPanel File Manager, copy (don’t move) two files from the subdirectory where you have WordPress installed to the root directory (i.e. the public_html directory):

  • index.php (you may also need to delete an index.html file if you have one in the root directory – back it up first just in case)
  • .htaccess (if you can’t see this, enable hidden files in CPanel by returning to the CPanel Home screen, clicking on File Manager and ticking the ‘Show Hidden Files’ box when opening File Manager).

3. Edit the index.php file

Open the index.php file in the root directory – the one you just copied across. Find the following line:

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

Change this line to:

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

– where ‘subdirectory’ is the name of the subdirectory where WordPress is installed.

4. Tell WordPress where the site is now

Back in the WordPress dashboard, go to the General Settings screen by clicking Settings -> General. Change the entry for the site address to the site’s domain name (ie. delete the subdirectory). The entry for the WordPress address stays the same. Click ‘Save Changes’.

5. Test it and go and make a cup of tea!

That’s it – the whole process took no more than five minuets from beginning to end (not counting the backup). You didn’t have to touch the database, only two files were moved and one small edit made. For more on this process (and to prove it’s not just something dodgy I made up), you can see instructions on the WordPress codex too. These instructions turn the process on its head, assuming you’re starting with WordPress in the root directory and want to move it to a subdirectory – but are basically the same.   If you’re looking for an agency with experience in developing custom WordPress sites, Compass Design can help. To talk about your requirements, please call Rachel on 07858 378178 or email rachel@compass-design.co.uk.

Posted in WordPress