How to move WordPress from a subfolder

This article will take you through the process of moving your WordPress website from the subfolder yourdomain.com/wp to the domain root – yourdomain.com:

for cPanel paper_lantern theme
for cPanel x3 theme

NOTE: Before proceeding with any changes, make sure that you generate a full backup of your website. If you've created your site using Softaculous script installer, feel free to refer to this guide as well (step #4 – Backup software).



for cPanel paper_lantern theme:
Re-installation
Redirection
File migration and Database update

Re-installation

If you just installed your website and have done no or little development, WordPress re-installation will be the easiest way out.

You just need to go back to cPanel > Exclusive for Namecheap Customers section > Softaculous Apps Installer menu:



Create a new one, make sure the In Directory field is empty and proceed with the installation:



Do not forget to uninstall /subfolder website by hitting the red cross in All Installations menu:




Redirection

If the website is pretty much done and re-installation is not acceptable, you can set up a hidden redirect – the installation will remain in the subfolder, but your website homepage will be yourdomain.com.

Take into account that this redirect will make /subfolder disappear only on the homepage, links will still have it – e.g., yourdomain.com/subfolder/contactus.

If it sounds alright to you, add the following redirect to .htaccess file in the domain web root (replacing yourdomain.com with your actual domain name and subfolder with your subfolder):

   RewriteEngine On
   RewriteCond %{HTTP_HOST} ^(www\.)?yourdomain.com$
   RewriteCond %{REQUEST_URI} !(/|\.[^/]*)$
   RewriteRule (.*) http://www.yourdomain.com/$1/ [L,R=301]
   RewriteCond %{HTTP_HOST} ^(www\.)?yourdomain.com$
   RewriteCond %{REQUEST_URI} !^/subfolder/
   RewriteRule ^(.*)$ /subfolder/$1


1. Navigate to Files section > File Manager:



2. Move to the root folder for your WordPress installation – public_html in case it is the main domain for your account.

Once there, make sure that Show Hidden files (dotfiles) option is enabled in Settings menu:

< br>
3. Locate .htaccess file, right-click > Edit:



4. If there is no .htaccess file located in your File manager, feel free to create a new one using File option:



You are ready to add the redirect rule and save it.



File migration and Database update

If the option above does not work for you, and you would like to make sure there is no /subfolder on your website, you can go this way.

NOTE: We highly recommend to back up website files and the database before proceeding.

1. File migration

Go to your website folder using FTP or File Manager:





Select All files > Move them to the domain document root (in our example, from public_html/wp_subfolder to public_html):





Once done, go back to the domain document root to make sure all files have been moved:




2. Database update

You can update old URL references with the new ones in the database either using search and replace scripts or using text editors. Below we provide the guidelines using the latter:

1. To begin with, you will need to locate the database associated with your website. Right-click on the file > View or Edit option:



You will see the database name in this line:



3. The next steps is to download the backup of the database. It can be done in your cPanel > Files section > Backup menu:




4. Unzip the downloaded file. Now you can open .sql file with some text editor and update all the URL references.

Hit Ctrl + F and select Replace option. Fill out the corresponding fields, Find – your old domain, Replace – your new domain) and hit Replace All:



5. Once done, you should get the output like this:



Make sure that you save the changes.

6. Now you can upload the updated database to your cPanel account. To be on the safe side, we suggest creating a new database (instead of dropping the existing one) and connect it to your WordPress side.

To do so, move to Databases section > MySQL Databases menu:



7. Follow the steps below to create a new database and user for it:







Keep these details, you will need to use them a bit later.

8. After that you can upload the database using phpMyAdmin menu in Databases section:



9. Select the newly created database from the list on the left and use switch to Import tab. There you will need to use Browse option to pick up the database .sql file from your local device:



NOTE: If your database is more than 50Mb, import the database following the steps in this guide.

10. Once done, you will need to update wp-config.php file in your installation root folder:



The fields to be changed are:

define 'DB_NAME' line – the name of the new database you've created in MySQL Databases menu.
define 'DB_USER' line – the name of the new user you you've created in MySQL Databases menu.
define 'DB_PASSWORD' line – the new password you've set for database user in MySQL Databases menu.



Save the changes and feel free to check your website.

If everything is working fine, you may delete the old database you used for the website.

11. It is also advised to re-generate the permalinks to make sure they have the new URL. You can do it in your WordPress dashboard in Settings menu > Permalinks.

So if you had Post name, you need to switch it to Plain, for instance, save the changes and then revert everything back:





for cPanel x3 theme:

Re-installation
Redirection
File migration and Database update

Re-installation

If you just installed your website and have done no or little development, WordPress re-installation will be the easiest way out.

You just need to go back to cPanel > Software/Services section > Softaculous > WordPress, make sure the In Directory field is empty and proceed with the installation.

Do not forget to uninstall the /wp website in Softaculous once done:




Redirection

If the website is pretty much done and re-installation is not acceptable, you can set up a hidden redirect – the installation will remain in the /wp subfolder, but your website homepage will be yourdomain.com.

Take into account that this redirect will make /wp disappear only on the homepage, links will still have it – e.g., yourdomain.com/wp/contactus.

If it sounds alright to you, add the following redirect to the .htaccess file in the domain web root (replacing yourdomain.com with your actual domain name and wp with your subfolder)

   RewriteEngine On
   RewriteCond %{HTTP_HOST} ^(www\.)?yourdomain.com$
   RewriteCond %{REQUEST_URI} !(/|\.[^/]*)$
   RewriteRule (.*) http://www.yourdomain.com/$1/ [L,R=301]
   RewriteCond %{HTTP_HOST} ^(www\.)?yourdomain.com$
   RewriteCond %{REQUEST_URI} !^/wp/
   RewriteRule ^(.*)$ /wp/$1



File migration and Database update

If the variants above do not work for you, and you would like to make sure there is no /wp on your website, you can go with this option.

We highly recommend to back up website files and the database before proceeding.

1. File migration

Go to your website folder using FTP or File Manager:



Select All files > Move them to the domain document root (in our example, from public_html/wp to public_html):





Once done, go back to the domain document root to make sure all files have been moved:




2. Database update

You can update old URL references with the new ones in the database either using search and replace scripts or using text editors.

Below we provide the guidelines using the latter.

  • Check what database is used for your WordPress website. You can check it in the wp-config.php file located in the WordPress installation folder:



  • Go to cPanel > Databases section > phpMyAdmin.

  • Select the database in question and click on Export > Go:



  • The database will be downloaded to your computer. Now you need to open it and update all yourdomain.com/wp references with yourdomain.com.

    Once opened, click Ctrl+F and choose the tab Replace. Fill out the fields below correspondingly > Replace All:



  • Once done, the prompt below will display the result:



  • Save the updated database and exit the application.
  • Now go back to cPanel > Databases section > phpMyAdmin and select your database.
  • Check all tables using the option below and select Drop from the drop-down menu:



  • On the next page, confirm the actions by clicking Yes:



  • Once the old tables are dropped, go back and select the database > Import:


  • Choose the updated database from your computer files to upload > Go:



  • You will see a green status bar - this will indicate that the database has been successfully imported. On your right, a database tables tree will appear:

  •  

    Go back to your website and refresh the page to check the results:



    That's it!

                  
                          Need any help? Contact our HelpDesk

    Updated
    Viewed
    54141 times

    Need help? We're always here for you.

    notmyip