moving wordpress from sub directory

Moving WordPress from Sub-Directory to Root Directory

In my blog post How do I move WordPress from a sub directory to root directory, I describe a process in which you don’t have to physically move the WordPress installation but can make a few settings changes in order to have the URLs for posts and pages display from the root while leaving the WordPress application and uploaded files in the subdirectory. This is a great strategy if you want to keep your directory structure clean, avoid having to rewrite a lot of URLs, and don’t want to deal with moving a bunch of files around on the server.

However, you may not want to use the subdirectory any longer and instead really do want to migrate WordPress from the subdirectory to the root directory. Below are steps to accomplish this.

(Tip: Instead of the process below, you can use the Duplicator plugin to create an archive zip of the entire site and restore the archive in the root directory. The benefit of using the Duplicator plugin is that the restore script will automatically rewrite all the URLs for you. However, duplicating a very large site might be a bit onerous and the archive process might not work well on some web hosts that have potential to time out when creating large archives.)

Before migrating WordPress from subdirectory to root directory

1 – Be sure you have access to your web hosting control panel and File Manager within the control panel as well as access to phpMyAdmin should you need to revert the changes you make to the WordPress General Settings below.

2 – Make a back up of your database using UpdraftPlus or BackWPUp plugin. Download this file and keep it safe.

3 – Remove any old site files from the root directory — perhaps copy them to a folder called _backup – this includes an index.html file which will totally make this process not work. You MUST remove all those old site files and folders or move them into another directory, so they don’t interfere with WordPress. Having an index.html and index.php in the same folder causes confusion, and likely, the index.html will be used instead of WordPress’ index.php file;

4 – 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” unless of course this is the name of your subdirectory install of WordPress in which case you cannot have a page of the same name because the browser will get confused and look for that page in that folder, then things are really confused.

5 – If you are using a caching plugin, delete all cached pages and de-activate caching.

Moving WordPress installation from subdirectory to public_html directory

1 – 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 / . Both addresses should simply end with .com or .org or whatever the domain type is. Click Save Changes.

general-settings

2 – Using FTP or the web host’s File Manager, you will need to MOVE all of the WordPress files from the sub-directory up one level to the root.

To do this with FTP, in the remote server area, toggle open the sub-directory containing the WordPress installation you wish to move. Select all the files in this directory and drag them out of this directory and into the public_html folder or whatever directory this directory is within.

If you are using the File Manager on the web host’s control panel:

– Double click the sub-directory containing the WordPress files.

– Click Select All to select all the files.

– Click Move File.

– In the Move dialog box, remove the sub-directory from the path field, so the path you are moving to is /public_html

(Note: Some hosts might have a different name for this folder or you may have installed WordPress in a sub-directory inside another directory. Just remove the current sub-directory from the path along with the forward slash /, but don’t remove anything more than that.)

– Click Move Files.

The files should now be moved to the public_html.

file-manager

3 – Login to WordPress in the root directory which should be your domain name plus /wp-admin, e.g. http://mywebsite.com/wp-admin.

4 – Go to Settings > Permalinks and click Save Changes. This will rewrite your .htaccess file to remove the subdirectory from the page URLs.

5 – Install the Velvet Blues Update URLs plugin.

Under Tools > Update URLs, type the website address containing the sub-directory in the Old URL field and the website without the sub-directory in the New URL field.

Be sure to not end the URLs with a forward slash /. If you do end it with a forward slash, end it with a forward slash for both URLs not just one. 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.

6 – 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.

Update urls

7 – Check for other URLs not caught with the Velvet Blues plugin including:

– Appearance > Menus — check for any custom URLs to the old site URL in any custom menu items, such as the home page link.

– Appearance > Theme Options or your theme’s Theme Options page — check the URLs for any uploaded files such as the logo or favicon and remove the sub-directory from the URLs as needed.

– Sliders — If you use Revolution Slider or other slider plugin may not update the URLs to the slider images with the Velvet Blues plugin. Edit the slider and remove the sub-directory from any image URLs.

– Shortcodes and custom layouts — Some shortcodes for button links or custom theme layouts may contain URLs to the sub-directory 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.

8 – Test the site and be sure everything is appearing as expected.

9 – Reset the caching and update the .htaccess file per the caching plugin instructions as needed. Test the site again in a different browser to be sure the pages are caching correctly.

10 – 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 sub-directory 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 %{HTTP_HOST} ^mydomain.com/subdirectory$ [OR]
RewriteCond %{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 Rewrite Rule 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 sub-directory in it and make sure it rewrites to the same URL without the sub-directory. 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.

Collected from askwpgirl.com

Comment (1)
Ahsan
February 17, 2017

Nice post. thanks for this post. Its helps me to migrate my website subfolder to root folder.

Reply

Leave A Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.