Move WordPress blog from Subfolder to Root Folder

How to move a WordPress blog from Subfolder to Root Folder

It is often debated if you would want to have your blog on a subfolder or your blog on the root folder. If you ask me, both are great ideas but it is vital to study the requirement of your blog or website. If your blog is maintained to give corporate or industry updates on your company’s behalf, its better to have the blog as a subfolder of your website but if its a dedicated blog, why not have it on the root?

WordPress is highly Search Engine Friendly because of its neat code and solid framework structure. Hence it is advisable to have the WordPress blog on the root folder (inside public_html) of your website as it would do good right from the home page in terms of SEO.

How to move a WordPress blog from Subfolder to Root Folder

Why I decided to migrate my blog from a subfolder to the root directory?

I started this blog in around the year 2006 when it was aimed at providing simple updates, news etc. on my web design company’s behalf. Going forward, I discovered the power and potential of a WordPress blog and the blog gradually shaped into a webmaster blog and forum. The webmaster community’s traffic started to improve significantly, thus I started to take the blog seriously by separating my web design service from this webmaster blog.

The blog was smoothly working on the sub-folder for quite few years without much problems. I had set up a 301 redirect from the root folder’s .htaccess file automatically redirecting all users “hitting” homepage to the blog sub folder. This worked just fine but I always knew it was not a great idea! It was obviously a workaround that slowed down the website, confused the SEO bots and more importantly I could not get to do proper SEO for the website as the first hit itself was a redirect.

How I moved my WordPress blog from the Sub-folder to the Root Folder?

Finally, I made up my mind to move the blog from the sub-folder to the root! It was a risky move as the blog was one of my largest blogs with more than 2000 articles, 12000 comments and loads of images. Change is inevitable – good or bad, I moved on!

Step 1: Always take back up of FTP and database: Be it what ever change you are going to do on your website or blog, its a GREAT habit to take a backup. Export the database locally and create a backup folder in file manager to save a copy of your live blog folder.

Step 2: Disable URL altering plugins: Disable plugins like the Cache plugins, broken link checker plugins etc. that could alter your URLs while active. Only proceed to the below step after disabling especially the WordPress cache plugins.

Step 2: Change the Site URL to the new one in the Admin Dashboard: Login to your admin dashboard and navigate to Settings – > General and you will be at the page as shown in the below screenshot. Here update the two fields – “WordPress Address” and “Site Address” to the new one (change from websitename.com/blog to websitename.com).

As soon as you save the settings, you might get a 500 Internal server or page not found error. This is basically because the URL of the website has changed. No issues, ignore that error and move forward to the next step.

How to move a WordPress blog from Subfolder to Root Folder

Step 3: Move the contents of the “Blog” folder to the Root folder: Login to your control panel (Cpanel) and open the file manger. Further move the contents of the “Blog folder” (in which subfolder your wordpress blog files are situated) to the root folder (inside public_html).

Once the moving is completed, you will be able to load the blog fine in the new URL (root domain) but the images might not load as the URL to the image / media files needs to be corrected in the database. As shown in the image below, the blog folder contents needs to the root folder.

How to move a WordPress blog from Subfolder to Root Folder

 

Step 4: Correct the URL in the required Database tables: This is an important step because the files have moved to the correct location but the content on the blog is linking to the old location. This causes the images to fail to load and to fix this the URL needs to be corrected in the DB. Backup the database and run the below query to update the required areas where the URL needs to be updated to the new ones.

Step 5: Ensure the default .htaccess file content on WordPress default is as below: The WordPress root folder / blog folder home will have a .htaccess file. Ensure that the .htaccess file should have the below content (default WordPress content).

How to move a WordPress blog from Subfolder to Root Folder

 

# 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

Step 6: Login to the WP dashboard and update permalinks: Login to your wordpress dashboard at the new link (root folder) and update your permalinks settings as there has been change in URLS.

UPDATE wp_options SET option_value = REPLACE (option_value,’http://www.websitename.com/subfolder’,’http://www.websitename.com’)

UPDATE wp_posts SET post_content = REPLACE (post_content,’http://www.websitename.com/subfolder’,’http://www.websitename.com’)

UPDATE wp_posts SET guid = REPLACE (guid,’http://www.websitename.com/subfolder’,’http://www.websitename.com’)

Note: Replace the “websitename” with your “domain name” & “subfolder” to your respective earlier “subfolder name”

Summary: Once the query is executed, it is expected that all the required URLs get updated to the current / latest ones. Also give a cross check manually in the table randomly and you are done. Finally, to resolve remaining 404 issues, once again navigate to Dashboard > Settings > Permalinks and just click “Save Changes” in order to get the permalinks to resolve correctly.

Ideally this should complete your navigation, now activate your plugins and clean up, test every aspects of your blog to ensure its all working before calling it success. Let me know if you face any difficulties in between this task and I will be happy to help.