Moving your WordPress from a subfolder to root is a great idea and practical too. Why? Because of a higher Page Rank. Usually websites that are located in domain root performs better on search engines.
In the following tutorial we will teach you how to safely move your WordPress to root and redirect every visitor from your old links to the new ones. Here are few examples of what you are going to do.
Move your WordPress from "/blog" folder (or from any folder you have your WordPress installed)...
... to your domain root.
And redirect old links
example.com/blog/?p=9586 or example.com/blog/fancy-permalink
To new links
example.com/?p=9586 or example.com/fancy-permalink
Pretty simple, but hard enough so let's get started. Remember to not rush things up, be careful to not delete something and follow the steps one by one. Also is important to do a full backup before doing this.
Before starting the process, be sure to backup your WordPress, root files and SQL databases. You can save everything to your computer very easy from cPanel. Check the images below.
After backup, make sure to move your root files to another folder in order to not overwrite with your WordPress files.
If you are running a portfolio in your domain's root, simply move every file to another folder, doesn't matter if it's htaccess, styles, index files, images, and let space for WordPress migration. You can change paths later in these files.
If you are running another WordPress in root folder, you can follow the same steps on moving.
Now that you have the SQL file to your computer, you will need to create a new database with all the links updated.
Simply clone/copy the SQL file anywhere you want on your computer to let the original intact and open the cloned file with any editor that have the Find and Replace Function. We used Notepad++ because opens big files very fast.
So we are looking to find and replace the old links (example.com/blog) with the new ones (example.com).
In the example below we will use our domain. Simply click "Replace All" to replace all links.
In the SQL file there are still paths which are using your server paths. You'll need to replace that too.
Below is an example of this kind of paths. As a solution you can search by word "blog/" which is not so accurate or you can search in steps for example, replace a longer word "public_html/blog" with "public_html", replace and after you can search again for the word "blog/"
Every path which contains your folder name, should be deleted. See a sample path below.
After cleaning everything, you can upload your new SQL file to your server.
Using MySQL Database Wizard from cPanel , you can create a new database very easy. While creating your database do not forget to check all privileges when requested.
Great! Your new database is up and running. Now let's upload the SQL file to the database using phpMyAdmin.
Using cPanel's File Manager, do NOT move all the files because you will need the WordPress intact to redirect old links on the new links from root. Simply just select all files and copy them to root location.
After creating the new database you need to point the WordPress to this new SQL Database. In the root folder where you moved your WordPress you will find a file called "wp-config.php". Here are the MySQL settings (username, password, database name etc.). Open the file with any text editor you like and update MySQL settings with the new names and passwords.
// ** MySQL settings ** //
define('DB_NAME', 'new_db_name'); // The name of the database
define('DB_USER', 'new_user_namet'); // Your MySQL username
define('DB_PASSWORD', 'new_user_pass'); // ...and password
define('DB_HOST', 'localhost'); // 99% chance you won't need to change this value
If you have W3 Total Cache Plugin or something similar for caching, these plugins are rewriting your .htaccess file with absolute path of your blog. Make sure to check the .htaccess file to identify these paths and delete the folder where your old WordPress points. If you don't change the .htaccess all posts from your new blog may redirect to your old blog.
In the example below the old WordPress was in the "blog" folder. Simply delete it together with the front slash ("blog/") and save the file.
Great! Now your new moved WordPress should work perfect if you changed all your links and paths correctly.
The last thing is to redirect the old blog posts to the ones from the root.
For example you want to redirect this:
example.com/blog/?p=9586 or example.com/blog/my-new-post
example.com/?p=9586 or example.com/my-new-post
Grab this plugin http://wordpress.org/plugins/redirection/ and install it to your old blog (/blog/wp-admin) .
After installing the plugin, you will find it in the Tools Tab. Write the following settings:
Source URL: /blog (old wordpress folder name) Match: URL Only Action: Pass-through Regular expression: Checked Target URL: /
Copy the code below right under the <head> tag in header.php file (should be in the theme folder you are using which is located in wp-content/themes).
After finishing your work, you can finally test everything. Please note that some Text Widgets may dissapear. If that happens, you still have the widgets from your old blog, so you can copy paste the text.
If this tutorial was useful, you can help me maintain this website with more tutorials by buying me a coffe (or at least the sugar).