Move wordpress from sub-directory to root while keeping the same url pattern

Hi Folks,

Recently I moved my wordpress blog from sub-directory (/root/blog/) to root (/root/) directory. Once I moved to root directory the blog url structure get changed from /blog/poast1 to /post1 and that leads to reduce the SEO from google and 404 error.

So in this post, I’m gonna describe how to move wordpress from sub-directory to root while keeping the same url pattern which means without affecting SEO or facing 404 error.

 

Step 1: Before start the mission, let’s take the backup

  1. WordPress folder – zip the “blog” folder
  2. WordPress database – Select all the table of the db and export it as sql file. (if you are using phpMyAdmin).

 

Step 2: Setup the folder structure 

Now move the all the files and folders from sub folder to root folder. Make sure that you don’t have any files or folder in root directory with the same name of sub directory files or folder.

Delete the sub directory folder. (if not this will cause a problem when adding Custom Structure of permalink)

 

Step 3: Setup the database

This is a little bit of tricky but easy to do 🙂

Drop all the tables of the wordpress database (Note: not the database)

Now we need to restore the database with the new url structure

  1. Open the back-up database file and open in a text editor.
  2. Find and replace the “website_name/sub-directory/” with “website_name”
  3. Still there may be some url with “/blog/”. Find and and remove the “/blog” part from there.
  4. Save and import the sql file to your wordpress database.

 

Step 4: Bring the old url format back

Go to Settion –> Permalink and set the Custom Structure as /”sub-directory name”/%postname%

wordpress_move

Note:

1. If you forgot to delete the sub-folder, you well get 404 error when accession the posts. It’s because the site looking the content from that sub-folder not from WordPress blog and the folder is empty.

2. You no need to change the WordPress Address (URL) ,Site Address (URL) from Setting  –> General tab menu. It should be mapped to your site_name (eg: sriajith.info)

Hope you folks managed to complete the mission successfully. If you have any problem please leave a comment below. 🙂

 

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: