How to move WordPress from a sub-directory to the root
Thought I’d share the process as I just recently recently relaunched my site from a development subfolder.
Before migrating
- Double-check you still have access to your web host’s control panel and File Manager / FTP. I prefer to use FileZilla FTP over File Manager. You will also need access to phpMyAdmin should you need to revert the changes you make to the WordPress General Settings below.
- Make a back up of your old database and new database using a WP plugin such as UpdraftPlus or BackWPUp or use cPanel. Download and keep this file safe!
- Make a copy of your old site via FTP and keep it somewhere safe with the old database, then remove any old site files from the root directory. You might want to just copy them to a folder called _backup on the server. This includes index.html!! Be sure to remove or move all those old site files and folders so they don’t interfere with WordPress. Having an index.html and an index.php in the same folder can cause server confusion. Make sure to also remove/move the old .htaccess file too!
- Similarly, make sure you don’t have any other folders in the root directory that have the same name as any pages on your WordPress site, for example “blog”. Make sure all the old site folders have been backed up and deleted or completely moved to the new _backup folder on the server.
- If you are using a caching plugin on your new site, delete all cached pages and de-activate caching.
Move WordPress from the subdirectory to public_html directory
- In your new wordpress site, go to Settings > General and remove the subdirectory from the URL for both the WordPress Address and Site Address. Be sure to remove the trailing / too. Both addresses should simply end with .com or .org or whatever the domain type is. Click Save Changes.
- Using FTP or your web host’s File Manager, you will need to MOVE all of the WordPress files from the subdirectory to the root. The files and folders should now be in public_html.
- Login to WordPress in the root directory by typing in your domain name plus /wp-admin, e.g. http://mywebsite.com/wp-admin.
- Go to Settings > Permalinks and click Save Changes. This will rewrite your .htaccess file to remove the subdirectory from the page URLs.
- Install the Velvet Blues Update URLs plugin to change the links in the database to reflect the new URL.
Under Tools > Update URLs, type the website address containing the subdirectory in the Old URL field and the website without the subdirectory in the New URL field. Be sure to not end the URLs with a forward slash /. Consistency is important here. Be sure to NOT not update all GUIDs. This will result in many theme settings to reset and posts to republish to the RSS feed. - Click the Update URLs button. This should catch most of the URLs on the site. However, if it seems to miss several, you can try repeating this process without the http:// part of the URL, and see if it catches more.
- Some other URLs to check for that are sometimes not caught with the Velvet Blues plugin:– Appearance > Menus — you may have some custom URLs to the old site in your custom menu items, like the link to the homepage.– Appearance > Theme Options or your theme’s Theme Options page — your uploaded theme files may still be linked to the old url, such as the logo or favicon. Remove the subdirectory from the URLs as necessary.– Sliders — If you use Revolution Slider or other slider plugin may not update the URLs these may have been overlooked by the plugin. Edit the slider and remove the subdirectory from any image URLs.– Shortcodes and custom layouts — Some shortcodes for button links or custom theme layouts may contain URLs to the subdirectory which you may need to manually change. If you can find a pattern to these, you can try to run the Velvet Blues plugin again using the URL pattern you find.
- Test the site and be sure everything is appearing as expected.
- Reset the caching and update the .htaccess file per the caching plugin instructions if needed. Also test your site again in a different browser to be sure the pages are caching correctly.
- Finally, to keep from losing all your SEO credit on the old site, you will want to implement a wild card redirect from the old URL to the new one. To do this, add the following bit of code to the top of your .htaccess file using the File Manager or FTP application substituting YOUR domain name and subdirectory name. (Note: .htaccess is an invisible file. You must select in the File Manager or FTP client to show invisibles in order to see this file.)RewriteEngine On
RewriteCond {a9f0d31f6175b3e4775e11a66c07db268fb74408d6095f6b46eeec420c0e9f62}{HTTP_HOST} ^mydomain.com/subdirectory$ [OR]
RewriteCond {a9f0d31f6175b3e4775e11a66c07db268fb74408d6095f6b46eeec420c0e9f62}{HTTP_HOST} ^www.mydomain.com/subdirectory$
RewriteRule (.*)$ http://www.mydomain.com/$1 [R=301,L]On the RewriteRule line use www or don’t use www according to what you have in your Settings > General. For example, if you don’t have www in your URL in the General Settings, do not include the www in the RewriteRule line.Pro tip: To start, set this rule to 302 instead of 301 and test it to make sure it is working by entering one of your URLs with the subdirectory in it and make sure it rewrites to the same URL without the subdirectory. When you are sure it is working, change the 302 to 301. 302 is considered temporary and is not used for SEO and is not cached by browsers. 301 is considered a permanent change and is considered by Google to transfer the SEO credit of a page from one URL to another and is cached by browsers.
Huge thanks to WordPress Girl for the great instructions!
Jeff
Wow! Thank you so much! I was stressing about how much time and how complicated this process would be. I just followed the instructions and after backing up the old files and database I had my site moved from subdirectory to the root level somewhere between 5-10 minutes!
olivia
Fantastic, Jeff! I’m glad it was easy. My first time moving a WP site was really daunting too.