Moving WordPress from Subdirectory to Root – FAQ

If you followed the instructions in my post “How do I move WordPress from a subdirectory to the root directory?” and you encountered any issues, please read the following list of frequently encountered issues.

Please comment below if you continue to have problems or write to me via my Contact form if you need personal assistance. If I can help you in less than 15 minutes, then I’m happy to do so for free. If the problem is more involved than that and requires me to login to your site and do the fix for you, then I charge $75/hour. Usually, I can solve these problems in less than 1/2 hour.

Verify the following:

1 – Index.php location and settings

Please check: Which index.php file did you move and where did you move it? The index.php file you moved should start with the following code:


<?php
/**
* Front to the WordPress application. This file doesn't do anything, but loads
* wp-blog-header.php which does and tells WordPress to load the theme.
*
* @package WordPress
*/

/**
* Tells WordPress to load the WordPress theme and output it.
*
* @var bool
*/
define('WP_USE_THEMES', true);

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

Check the require line in your file. Be sure that the / are in the right place and that the subdirectory name is correct. Most people make a mistake and either don’t edit the require line and put their subdirectory name in it or make a mistake with the syntax and have an extra slash, no slash, an extra period, etc.

Next, where did you put this index.php file? Some people have put it in the root of the hosting account instead of in the domain root — which is the public_html folder on most hosts. If you moved this file outside the public_html folder, that won’t work. Some people’s hosting accounts are really wildly configured, and their host does not have a straight forward path for you to figure out where the heck your domain root is. So, to keep things simple, you would have wanted to move the index.php to the directory just above your subdirectory that contains the WordPress application.

Finally, some people have inadvertently moved the index.php file in their theme’s folder rather than the index.php file in the subdirectory. If you don’t see the require line above in your index.php file, then you moved the wrong file.

2 – WordPress General Settings

The next most common mistake is to not set the General Settings in the WordPress Dashboard correctly. Here is how they should have been set:

If a mistake was made here, then you might not be able to see your site or you won’t be able to login to your site. It is pretty common to have made a mistake with these settings or forgotten to make the change here. To fix this, you will need to login to your phpMyAdmin application via your web hosting control panel. Take note of your database username and password in the wp-config.php file and check the following:

Login to the database and go to the wp_options table and click the browse tab.

The first option is is for siteurl (which is totally inconsistent with the General Settings field label). This should be set to the URL with the subdirectory:

Go to the next page of the table and check the home value. This should be the URL to the main site URL without the subdirectory name:

3 – .htaccess

Some web hosts will have issues with the .htaccess commands once your index.php file is in the public_html file. If this is the case, you should still be able to login to WordPress via the subdirectory, and your home page will display correct BUT your links to the other pages will show a “Page Not Found” error. (Please note: even though you are showing the pages of your site from the main domain url, you will still need to login via the subdirectory url – e.g. http://yoursite.com/mywp/wp-admin – and all of your images on the site will still be located in the http://yoursite.com/mywp/wp-content/uploads.)

So, if you are having troubles with your “pretty permalinks” in other words, the home page of the site displays okay, but your subpages display a File Not Found message, then login to your WordPress dashboard and go to Settings > Permalinks and click Save Changes. This should cause your .htaccess file to be updated correctly. If this does not work, you may need to move the .htaccess to the root directory and manually replace the current WordPress mod rewrite directive with the code below. (Note: you will need to show invisible files via your FTP application or use the web host’s file manager to see this file.)


# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

IMPORTANT NOTE: If you are on a Windows hosting account (please check this before commenting below), you will NOT have an .htacccess file. You will need to install a web.config file to use the Microsoft’s Rewrite Module. For more information, please read: http://codex.wordpress.org/Using_Permalinks#Permalinks_without_mod_rewrite. If you are on GoDaddy and have Windows hosting, please read: http://wordpress.org/support/topic/godaddy-iis-and-removing-indexphp-in-url?replies=20#post-1507468

To determine if the permalinks is the issue with why your internal page links are displaying as Page Not Found, try to use the Default permalinks (Permalinks > Settings) and see if you can view all your interior pages fine. If you CAN view all your pages using the Default permalink settings (in other words, the pretty urls are turned off), then the issue is related to the .htaccess file on Linux/Apache hosting or not having a web.config file and rewrite rules enabled on a Windows server.

You may need to check with your web host about how to make this work properly. Some, such as Yahoo web hosting really are not good WordPress hosts, others require that /index.php be part of the permalink structure. So, if the default permalinks work, and you’ve tried creating and editing your .htaccess (Linux) or web.config file (Windows), then call your web host.

4 – PHP Version Called in the .htaccess file

One person who wrote to me had their php version command in their .htaccess file. They had deleted the .htaccess file after moving WordPress, so the PHP directive calling for the correct version of PHP was removed, and their site therefore was running PHP 4, and the latest WordPress will not run in PHP 4. This is something you can check with your web host, and they can give you the line that goes in your .htaccess file to call for the correct version of PHP. It will look something like this:


AddHandler application/x-httpd-php5s .php

5 – Old Site Files Interfering with New Site

Several people installed WordPress in a subdirectory because they had an existing site in the main url. When they followed these instructions to move the index.php file the WordPress subdirectory to the main site directory, they left the old site files in the main directory and therefore, the browser kept trying to open the old index.html file rather than the index.php file. To fix this, simply create a new folder called _OLD in your main directory and drag all of your old site files into this folder. Download this folder and then delete it from the server after you’ve verified that the site is functioning correctly. Do not leave these old files on the server unless you have excluded them from search engines via a robots.txt file.

6 – Redirecting Old URLs

Whether you had an old .html site up or had your current WordPress site in the subdirectory indexed by Google, you’ll want to do redirects on these pages that Google may have indexed.

If you had an old .html site and the WordPress site was “private,” after you’ve completed this process, be sure to change the Privacy settings in the WordPress dashboard, so Google can now index these new WordPress urls. Install the Redirection plugin and create redirects on the old .html URLs to their new WordPress URLs. Install the Google XML Sitemap plugin and generate a new sitemap and submit it to Google Webmaster Tools. This will help prevent any 404 Page Not Found errors. Google will eventually re-index your site with the new URLs, so you shouldn’t have those old URLs come up in search engine searches after a few weeks.

If your current WordPress installation was indexed by Google with the old URLs, eg http://yoursite.com/mywp/about and now it is http://yoursite.com/about, then you will need to do the same as above for those old URLs. If you have a LOT of these old URLs, ie, you had a large, active blog before you followed these instructions, I’m testing out an .htaccess command you can use to rewrite all the URLs. I’ll post it here when I’ve tortured tested it.

7 – Protecting the WordPress Directory from Browsing

Since we removed the index.php file from the WordPress directory, now that directory can be “browsed,” which is not good. To prevent this, add the following line to your .htaccess file:

Options All -Indexes

OR install the Silence is Golden Guard plugin

OR create a new blank index.php file in the WordPress directory which contains the following code:


<?php
// Silence is golden.
?>

8 – Internal Hyperlinks

Please note that this process does preserve all the image links in your site. However, you will need to reset any INTERNAL hyperlinks, including any manually entered hyperlinks in the Appearance > Menus.

Some themes have hardcoded the link to the Home page incorrect and you may need to set that correctly in the header.php file of your theme.

A good plugin for finding these broken links is the Broken Link Checker.

I have also used the Search and Replace plugin, but use it with caution, because you don’t want to replace your good image links.

Typically, I will search for <a href=”http://yoursite.com/mywp

and replace with <a href=”http://yoursite.com/mywp

then I’ll do another search to make sure I didn’t break any image links with <a href=”http://yoursite.com/wp-content

and replace with <a href=”http://yoursite.com/mywp/wp-content since the wp-content is and always will be in the mywp (aka the subdirectory).

  • AskWPGirl

    The change of the URLs to the root shouldn’t effect any of these things. I don’t see any images missing in the HTML. Did you do anything else besides what’s written in these instructions? I haven’t experienced any themes having issues with this process because WordPress is not moved and only the page URLs are writing from the root. Do you have a screenshot you can email to me of what it’s supposed to look like? Your nextgen gallery slideshow is not loading, either, and that is not related to the “move” but perhaps to something else you may have done in addition to what I wrote.

  • AskWPGirl

    Also, clear your browser cache and any page caches if you are using a caching plugin.

  • steve

    I just want to thank you for your tutorial which saved the day for me. I followed the WordPress codex but was confused with the inconsistent wording between the general setting tab and the database tables. I was able to correct the site url in the database table to the WordPress subdirectory to fix my error. You saved me a ton of research and headache. 

    You have a wonderful source of great information here – thanks!

  • AskWPGirl

    So glad that worked!

  • Paul

    Thanks for this tutorial I think it saved me a ton of time. I’m moving a site from a subdir to the root to replace the static html site. Everything works except, and I have the WP set for static front page and posts appearing on blog, when I go to blog there is nothing there. 
    All the other internal pages work. So I’m wondering if this method will only work for a blog per say as opposed to creating a whole site with a blog section?

  • AskWPGirl

    Hi Paul,

    Everything is there. If your link to your blog is not working then you might have created a custom link to that in your Menu and need to fix that to go to the http://site.com/blog rather than http://site.com/subdirectory/blog. Also, is the word “blog” the same name as your subdirectory? You don’t want to have any pages with the same name as the subdirectory — that could cause some confusion for WP and it won’t be able to figure what the heck you’re trying to find. You definitely do NOT need to create a whole new site for the blog section. Again, this is an error of either having the wrong link in your menu or using the same name for that page as your subdirectory name.

  • Paul

    OK, I knew I missed something. I just renamed to “blog” section, as that was the name of the old dir to “articles” and all is right with the world now. Thanks for the memory jog. ;)

  • AskWPGirl

    WordPress runs a query on the database to find out if the URL being submitted via the browser is a post, category, page, etc. But, the server folders are also considered, so when the names are duplicated, it can result in a 404 not found, because it just can’t make sense of what you’re looking for. I’m glad that was the answer!

  • Saed

    Thanks for the detailed instructions WPGirl!

    Wanted to ask if it possible to leave old static html pages in the root, instead of deleting them all (deleting just index.html to free the space for index.php doesn’t help). If I want to leave old htmls as they are
    on the site – is there an easy solution (probably involving .htaccess)
    to avoid this WP’s “index.php” and static htmls conflict? Or is it just
    easier to move all old htmls to a folder and make redirects to them from
    old locations?

  • AskWPGirl

    You can leave the old HTML in the root as long as they don’t have the same names as any of the pages on the WordPress site. For example, about.html will get confused with the same page called “about” in WordPress. So perhaps have the URL for the WordPress page be “about-us” instead. However, keep in mind that if the content is the SAME on these pages, you will get docked by Google for duplicate content. So if the purpose of the html pages is to refer to them but not to have them indexed by Google, it is better to put them in a separate folder. Then create a robots.txt file in the root that contains text to exclude this folder from search engine searching. Here’s a sample robots.txt file for WordPress:
    http://codex.wordpress.org/Search_Engine_Optimization_for_WordPress#Robots.txt_Optimization

  • Saed

    Thanks for reply!
    After trying to move my WP to the root the home page was just a blank white screen. Since I checked and double checked and redid all the steps – I thought that the problem was that my old static pages are in the root. But now I realise that they are not the problem – since I deleted them all and still have white screen instead of homepage.
    Don’t even know what the reason can be since I triple checked eveything. Will try to work it out.

  • Saed

    Hi again (I wrote a comment few hours earlier),
    I finally found what my problem was and thought maybe it will help others, who may also overlook this detail:
    In my WP theme (written by myself) the header in theme index.php was called with

    so I changed it to reflect the directory change to

    Thanks for your article again, good luck!

  • AskWPGirl

    Good point. I’ll add that to my FAQs. Sometimes people who write their own themes hard code URLs in the header which can cause problems. If you code your own themes, you should use the bloginfo template tag and use the parameter “stylesheet_directory” to reference the URLs correctly no matter what domain or directory the theme is in. This is how all of the themes on WordPress.org are coded as well as premium themes. For more information, read: http://codex.wordpress.org/Function_Reference/bloginfo

  • Saed

    Yeah, I better use stylesheet_directory in themes.
    That php code that I pasted to the comment box, unfortunately, didn’t display. BTW, excuse me for not keeping my comments in a single thread :) (delete them if necessary).
    Good luck!

  • Tim

    Hello. 

    Thanks for sharing such helpful tips about a topic that could be pretty overwhelming. I was wondering what the difference would be in the step if my subdirectory site was at wp.mysite.com and trying to get it to mysite.com? What would the “require” line in the index file look like since it doesn’t seem like it would recognize the changes. 

    Thanks again!

  • AskWPGirl

    Hi Tim,

    I recently did have to do something similar where I had set up store.mysite.com and needed it to be http://www.mysite.com. How we handled this was to point the A Record for the www site to store.mysite.com folder on the server since store was set up as a subdomain and had it’s own folder. Once that was done, I changed the URLs in the General Settings to www for each of them, then had to log in again and use the Search and Replace plugin to change all instances of http://store with http://www in the posts. This worked well. So, the instructions I wrote in the blog post you commented on really don’t apply in this situation since you aren’t “moving” WordPress – you’re simply changing the settings and making sure the domain is pointing to that folder, which is something your web host should be able to help you out with. If you already have a site in the www and pointing the www (or non-www as the case may be) to the subdomain folder is problematic, then you could use a plugin like BackupBuddy to backup the entire site. It has a nifty importbuddy.php file that you use to restore the site on the new domain. I use it all the time for migrations, and they have a great video tutorial. I would recommend getting it anyway to do regular full backups to the Amazon S3 cloud. My affiliate link for that is http://askwpgirl.com/go/backupbuddy.php

    I hope that helps. It really does depend on how your hosting and DNS is setup, but most of the time hosts are good about helping this sort of re-pointing of sites.

  • Andy G

    Thanks for this post, and especially step 8. I’ve done this specific move a couple of times (start in a subdirectory then make it look like the blog lives at the top-level domain). After the move it’s minor pain to deal with broken links that have been manually created between pages in the site’s content. 

    I wondered whether I was doing something wrong, since most tutorials just talk about the permalinks and don’t mention anything at all about broken internal links. I came up with the same method as you: search/replace once to update the internal links, then a second time to revert any wp-content links to the old structure.

    It was a relief to find your post and see the same process.

    One thing worth noting: according to Moving WordPress in the Codex (https://codex.wordpress.org/Moving_WordPress) we should only do this search/replace on the wp_posts table. Doing it on other tables, like options tables, can cause problems.

    BTW, your search/replace example in 8 might have a typo. I think you meant the “replace with” part to say a href=”http://yoursite.com/.

    Thanks again.

  • 4ever

    Hi, 

    On #6 you state, “I’m testing out an .htaccess command you can use to rewrite all the URLs. I’ll post it here when I’ve tortured tested it.”  DId you ever test this method?  We recently moved a site and have a different file structure with over 1000 posts. 

    Thanks

  • AskWPGirl

    I haven’t finished testing, but I have found some solutions by searching Google with the words .htaccess wild card 301 redirect. Here’s a good article by Perishable Press http://perishablepress.com/stupid-htaccess-tricks/

    It’s just important to not overwrite links to the wp-content folder which does stay inside the subdirectory. That’s the trick.

  • AskWPGirl

    Hi Andy, Very good point! I’ll modify the post to emphasize to only look in the posts table for the search and replace. I, too, have totally messed things up by searching and replacing all.

  • Janet Russel

    Just wanted to thank you so much for all the info you posted.  It was extremely helpful!!! I just started working with WordPress a few weeks ago.  I converted a site by creating a sub-directory and wanted to transfer it to the root.  I ran into all sorts of problems and your site saved me!  Thanks a million!
    Janet (Toronto, ON, Canada)

  • AskWPGirl

    Oh fascinating! I never consider file permissions issues factoring in. Good catch!

  • AskWPGirl

    So glad to hear that it worked for you!