WPBeginner

Beginner's Guide for WordPress

  • Blog
    • Beginners Guide
    • News
    • Opinion
    • Showcase
    • Themes
    • Tutorials
    • WordPress Plugins
  • Start Here
    • How to Start a Blog
    • Create a Website
    • Start an Online Store
    • Best Website Builder
    • Email Marketing
    • WordPress Hosting
    • Business Name Ideas
  • Deals
    • Bluehost Coupon
    • SiteGround Coupon
    • WP Engine Coupon
    • HostGator Coupon
    • Domain.com Coupon
    • Constant Contact
    • View All Deals »
  • Glossary
  • Videos
  • Products
X
☰
Beginner's Guide for WordPress / Start your WordPress Blog in minutes
Choosing the Best
WordPress Hosting
How to Easily
Install WordPress
Recommended
WordPress Plugins
View all Guides

WPBeginner» Blog» Tutorials» How to Properly Move WordPress From Subdomain to Root Domain

How to Properly Move WordPress From Subdomain to Root Domain

Last updated on October 26th, 2017 by Editorial Staff
162 Shares
Share
Tweet
Share
Pin
Free WordPress Video Tutorials on YouTube by WPBeginner
How to Properly Move WordPress From Subdomain to Root Domain

Do you want to move a WordPress site from subdomain to root domain? The process is fairly easy to follow, and there is a way to save your SEO rankings as well. In this article, we will show you how to easily move WordPress from subdomain to root domain with step by step instructions.

Moving a WordPress site from subdomain to root domain

Transferring WordPress from Subdomain to Root Domain

A subdomain is an extension of your root domain name. For example, http://yourwebsite.example.com is a subdomain of example.com. In this case, example.com is the root domain.

Search engines consider subdomain to be a totally different website. This is why you need to make sure that you properly redirect search engines to the root domain after the transfer. This will help you preserve search rankings after moving your website.

Unlike moving a WordPress site to new host or a new domain name, moving a site to root domain is a bit easier.

Primarily because both are usually hosted with the same web hosting company. This allows you to skip a few steps.

Let’s take a look at how to move a WordPress site from subdomain to root domain.

Step 1. Create a Complete Backup of Your Website

You should always keep a backup solution installed on your website for automated backups. There are plenty of WordPress backup plugins that you can use to keep your WordPress content safe.

Now if you already have a backup plugin installed, then you may be thinking that you can skip this step.

This step is to remind you that even if you have automated backups of your website, you still need to create a complete backup of your site. This includes a database backup as well as a backup of all your WordPress files and folders.

Once you have created a complete backup, make sure that you store it on a remote location or on your computer.

Step 2. Moving Your WordPress Files From Subdomain to Root Folder

First you need to connect to your website using a FTP client or cPanel’s file manager. Once connected, go to your subfolder location and download all your WordPress files to your computer.

Download WordPress files

Next, open the public_html folder of your root domain. Depending on how your WordPress hosting environment is setup, this folder could also be named www or after your domain name.

Now, you need to upload all WordPress files you downloaded earlier to the root directory.

Upload WordPress files to root domain

Step 3. Change WordPress URL and Site URL Settings

Once you move the WordPress files, you will not be able to access the WordPress admin area on the root domain. Trying to login to the root website will send you back to the subdomain website’s admin area.

To fix this, switch to the FTP client and go to the root directory of your domain name. Next, you need to edit the wp-config.php file and add the following lines just before the line ‘That’s all, stop editing! Happy blogging’.

define('WP_HOME','http://example.com');
define('WP_SITEURL','http://example.com');

Don’t forget to replace example.com with your own domain name. If you want your root website to use www then you will need to enter the URLs with www prefix.

Save your changes and upload the wp-config.php file back to your website.

You can now visit your WordPress site’s admin area on the root domain name.

Step 4. Update URLs

Your WordPress site has moved to the root domain, but there will be links inside your WordPress database pointing to the subdomain.

Let’s fix that.

You will need to install and activate the Velvet Blues Update URLs plugin. For more details, see our step by step guide on how to install a WordPress plugin.

Upon activation, you need to visit Tools » Update URLs page.

Update URLs

On this page, you need to enter your subdomain url next to the Old URL option and add your root domain as the new URL. Next, under the ‘Choose which URLs should be updated’ area, you need to check all options except ‘All GUIDs’.

Once you are done, click on the ‘Update URLs Now’ button to continue.

The plugin will now update all URLs in your WordPress database. This may take some time. Once finished, you will see a success message.

Step 5. Redirect All Subdomain Traffic to The Root Domain

Now that you have moved WordPress files, let’s make sure that your subdomain traffic is redirected to the root domain name.

Go to your subdomain folder and make sure that hidden files are forced to be visible.

Your FTP client settings have an option to always show hidden files. In FileZilla, it is located under ‘Server > Force Showing Hidden Files’ option.

Show hidden files

If you are using cPanel File Manager, then click on the Settings button at the top right corner of the screen. This will bring up the preferences popup. You need to select ‘Show hidden files’ and then click on the save button.

Show hidden files in cPanel file manager

If your subdomain folder already has a .htaccess file, then you can delete it and create a new one. Inside the new .htaccess file, you need to copy and paste the following code:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^yoursubdomain\.example\.com$ [NC]
RewriteRule ^(.*)$ "http://example.com/$1" [R=301,L]
</IfModule>

Don’t forget to replace yoursubdomain with your actual subdomain, and example.com with your domain name.

Please note that the RewriteRule line uses a non-www URL. If you want to use www in your root domain, then you will need to add your URL with a www prefix.

Save your changes and upload your .htaccess file to the server.

That’s all, you have successfully moved your site from subdomain to root domain. You can now visit your website to see it in action. Test out your website to make sure that everything is working fine.

We hope this article helped you move your site from subdomain to root domain. You may also want to see our ultimate WordPress SEO guide for beginners.

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

162 Shares
Share
Tweet
Share
Pin
Popular on WPBeginner Right Now!
  • How to Start Your Own Podcast (Step by Step)

    How to Start Your Own Podcast (Step by Step)

  • Checklist

    Checklist: 15 Things You MUST DO Before Changing WordPress Themes

  • How to Fix the Error Establishing a Database Connection in WordPress

    How to Fix the Error Establishing a Database Connection in WordPress

  • How to Properly Move Your Blog from WordPress.com to WordPress.org

About the Editorial Staff

Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi. Trusted by over 1.3 million readers worldwide.

The Ultimate WordPress Toolkit

50 Comments

Leave a Reply
  1. Del Abernethy says:
    Oct 15, 2020 at 10:02 am

    Worked a charm up until I tried to login to wp-admin. The site already had files (which I over-wrote) and users but now it won’t recognise the existing users. It does allow me to login using the username & password from the sub-domain so I’m assuming it is linked to the sub-domain database. Is it possible to link it to the existing original database?

    Reply
    • WPBeginner Support says:
      Oct 16, 2020 at 9:45 am

      You would want to check the wp-config file for the database it is connected to for your site and you would be able to change that in your file. That would normally happen if you didn’t overwrite the existing file if you were trying to replace a site with the one on the subdomain.

      Reply
  2. Peter Harrison says:
    Oct 14, 2020 at 4:26 am

    Does this method update all the references in the database too?

    Regards
    Pete

    Reply
    • WPBeginner Support says:
      Oct 14, 2020 at 10:30 am

      It would depend on what references you are talking about. If you mean links in the articles then the velvet blues plugin updates those.

      Reply
  3. Mucha says:
    Sep 28, 2020 at 4:06 pm

    please advise on the steps for the htaccess. if my subdomain is /new what should it be on the new htaccess?

    Reply
    • WPBeginner Support says:
      Sep 29, 2020 at 8:52 am

      You would want to take a look at step 5 in the article for that information.

      Reply
  4. Kat says:
    Sep 12, 2020 at 11:25 am

    I get a Web Application Firewall error whenever I implement phase 4. What could be the problem?

    Reply
    • WPBeginner Support says:
      Sep 15, 2020 at 11:39 am

      You would likely want to check with your hosting provider to ensure they don’t have a firewall and your SSL certificate is active as the most common reasons

      Reply
  5. Ben says:
    Sep 4, 2020 at 8:29 am

    Hey – do you reccomend also using Googles change of address tool, to tell it subdomain.primarydomain.com is now primarydomain.com ?

    thanks

    Reply
    • WPBeginner Support says:
      Sep 8, 2020 at 3:51 pm

      If you want you can also use that tool, the redirects would normally resolve this for you.

      Reply
  6. Sunita says:
    Aug 29, 2020 at 10:02 am

    Thanku so much… it wouldn’t be possible without your help… thank you again!

    Reply
    • WPBeginner Support says:
      Sep 1, 2020 at 9:55 am

      You’re welcome :)

      Reply
  7. Sara says:
    Aug 4, 2020 at 12:39 am

    Hi,
    I followed your steps up until the end of step 3, where I have edited the wp-config.php file
    I then go to the wp-admin. I enter my details and it just goes back to the same login. It’s not allowing me to login to the wordpress backend.
    It’s like it’s redirecting me.
    Are you able to help?
    I’d really appreciate it.
    Thanks,
    Sara

    Reply
    • WPBeginner Support says:
      Aug 4, 2020 at 11:14 am

      There are a few reasons for that, you may want to take a look at our guide below for some possible solutions:
      https://www.wpbeginner.com/wp-tutorials/how-to-fix-wordpress-login-page-refreshing-and-redirecting-issue/

      Reply
  8. Ghassen GaraAli says:
    Jul 7, 2020 at 6:22 pm

    Hello,

    Does this work to move a subdirectory to root ?

    thank you

    Reply
    • WPBeginner Support says:
      Jul 8, 2020 at 9:28 am

      Yes, you can follow our guide for that as well.

      Reply
  9. Sofia says:
    Apr 28, 2020 at 3:55 pm

    Hello, I did everything and it worked! But now I’m wondering, how do I keep my subdomain as a “staging” website, so that I can change things and not affect the one on the domain. I’d have to make a new database (using a backup) right?
    How to assure I don’t do anything wrong?

    Reply
    • WPBeginner Support says:
      Apr 29, 2020 at 10:13 am

      For setting up a staging site, you would want to take a look at our guide using the link below:
      https://www.wpbeginner.com/wp-tutorials/how-to-create-staging-environment-for-a-wordpress-site/

      Reply
  10. Oliver says:
    Nov 17, 2019 at 9:15 am

    In my subdomain folder, I have 2 .htaccess files. One is in subdomains/example, the other is in subdomains/example/web. The latter is next to all the other wordpress files. Which one should I delete and replace with the code in step 5?

    Reply
    • WPBeginner Support says:
      Nov 18, 2019 at 10:39 am

      You may need to check with your host but from the sound of it, you would modify the second one.

      Reply
  11. Aldo Salim says:
    Nov 14, 2019 at 2:00 am

    Hi, thank you so much for the great help.

    However, i do not want to keep the old sub-directory folder. Will it be okay to delete the sub-directory folder?

    Reply
    • WPBeginner Support says:
      Nov 14, 2019 at 10:12 am

      As long as you’ve moved all of the files you can remove the sub-directory folder

      Reply
  12. Joshua Orizu says:
    Oct 24, 2019 at 1:49 pm

    I am building a websites and the domain name is displaying site.comp50 instead of site.com how do i fix this

    Reply
    • WPBeginner Support says:
      Oct 25, 2019 at 9:40 am

      You may want to check with your hosting provider to ensure the correct domain is attached to where your site is and then you would be able to update the url in your Settings>General area

      Reply
  13. Jeremy says:
    Aug 20, 2019 at 10:59 am

    What happens to the blog posts on the root domain during a migration?

    I currently built a redesigned site on a subdomain, Sandbox.WebsiteName.com, and want to migrate it over to the the root domain. However, I want to keep the blog posts.

    i’m worried about the seo. Do the blog post from the root domain get overwritten? If not how would i access them to redirect them?

    Thanks,

    Reply
    • WPBeginner Support says:
      Aug 21, 2019 at 9:02 am

      This method would overwrite the old content on your primary site, for moving the site you could use one of the methods here: https://www.wpbeginner.com/wp-tutorials/how-to-create-staging-environment-for-a-wordpress-site/
      or you could import the content from your live site and then follow the steps in this article

      Reply
  14. Madison says:
    Aug 18, 2019 at 11:36 pm

    Hi,

    Would this method work if I wanted to move a subdomain, which a friend uses, ie, xxx.example.com, over to their new account so it can be its own website like xxx.com?

    If not, is there anything that would work at all or would they just have to start over, thus losing all the comments, page views, etc?

    Reply
    • WPBeginner Support says:
      Aug 19, 2019 at 11:27 am

      For that type of change, you would want to take a look at our article here: https://www.wpbeginner.com/wp-tutorials/how-to-properly-move-wordpress-to-a-new-domain-without-losing-seo/

      Reply
      • Madison says:
        Aug 19, 2019 at 2:24 pm

        Thanks! From what it looks like, all I need to do is not use Duplicator on my root domain but on my subdomain and everything should work the same, right?

        Reply
        • WPBeginner Support says:
          Aug 20, 2019 at 10:03 am

          That should be correct

  15. jeff says:
    Apr 2, 2019 at 2:13 am

    velvet blues didn’t work for me, but another url replacement plugin did (better search replace)

    Reply
    • WPBeginner Support says:
      Apr 2, 2019 at 11:16 am

      Thanks for sharing the plugin that worked for you :)

      Reply
  16. Rui says:
    Mar 30, 2019 at 9:12 am

    Hi,
    This tutorial is great, but didn’t work for me. I don’t know why.

    I can access to admin area, in homepage the images are not shown and when i tried to access posts and products says “Not Found
    The requested URL /shop/index.php was not found on this server.”

    I would like some help if possible.
    Thank you a lot

    Reply
    • WPBeginner Support says:
      Apr 1, 2019 at 11:54 am

      You may want to ensure steps 3 and 4 were completed for the most common reason for that.

      Reply
    • Canonical Bear says:
      Jun 19, 2019 at 3:57 am

      Hi,
      We had the same problem (my team and I). Only the Home Page would open, and all other pages were broken.
      You need to update the permalinks. Go to Dashboard ->Settings -> Permalinks. Here, don’t make any changes, just click on “Save Changes”.
      It re-apply settings with the current directory as root.
      All the best.

      Reply
      • John says:
        Aug 10, 2019 at 4:46 pm

        CANONICAL BEAR, you deserve two kisses for this comment. No, make that three! Worked superbly.

        Reply
  17. Milan says:
    Oct 3, 2018 at 10:59 am

    Hello WP Team,

    just one quick question… what is the difference between this procedure and clone website from cpanel installatron (godaddy). Can I use clone for same purpose? Do I need to made some additional changes after cloning. It’s looks much easier to do this with clone option.

    Thanks for good work!

    Reply
  18. Melind says:
    Sep 6, 2018 at 3:50 pm

    This worked like a charm! The part that takes the longest is uploading and downloading the files. Thank you!

    Reply
  19. smv says:
    Jun 4, 2018 at 8:15 pm

    This didn’t work for me at all. Step 4, using the Velvet Blues plug-in to update the URLs, didn’t update most of them. There were still loads of references to the old site. I had to re-do everything, but I used the duplicator plug-in, which worked well.

    Reply
  20. Gábor Sztárcsevics says:
    Mar 5, 2018 at 6:23 am

    Hi!

    Is this modification will change the records in the database, which is used for my wordpress on the subdomain.example.com?

    Shouldn’t I create a new database for the migrated wordpress?

    Thank you!

    Reply
    • WPBeginner Support says:
      Mar 5, 2018 at 9:15 am

      Hi Gábor Sztárcsevics,

      Since you are moving from subdomain to root domain on the same hosting environment, your old database would work just fine after you update URLs as shown in the tutorial.

      However, if you would like to create a new database, then you can do that as well. You will then need to export your data from the old database to the new one and update URLs.

      Reply
  21. Shravan says:
    Jan 3, 2018 at 7:10 am

    RewriteCond %{HTTP_HOST} ^yoursubdomain\.example\.com$

    in this code, do i need to remove those 2 backward slash’s

    Reply
  22. Denise says:
    Dec 17, 2017 at 7:22 am

    I don’t see where you remove the old wordpress files. Are they automatically replaced when you upload the subdomain files to the root?
    Thank you.

    Reply
    • WPBeginner Support says:
      Dec 17, 2017 at 8:22 pm

      Hi Denise,

      IF your root site already has a WordPress installation, then you need to overwrite those files.

      Reply
  23. Charlotte Jones says:
    Nov 15, 2017 at 1:56 pm

    I tried this and got a HTTP 500 error. Luckily I backed everything up, but I don’t understand. All the files are there in public_html and I changed the wp-config file to point to the root domain.

    Reply
  24. Jon says:
    Nov 6, 2017 at 1:53 pm

    Very good thank you. Went like a dream apart from an error I made by amending the old subdomain .htaccess file instead of the new one in the root. Your advice was excellent tho.

    Reply
  25. Juan F. says:
    Nov 1, 2017 at 11:33 am

    Hi guys,

    After doing all the steps, if I want to save a page I get an error and automatically redirects me to the post list, could you help me please?

    Thanks in advance.

    Reply
    • Anita says:
      Nov 18, 2017 at 12:36 am

      Hello!
      If I make the site in the exemple.com/Wordpress folder, do I have to move it to the example.com folder or can I just redirect it, how does that work?
      /Anita

      Reply
  26. Ousman Faal says:
    Oct 27, 2017 at 6:29 am

    This was definitely useful. I was just about to change a demo site on a sub domain to a root domain.
    You guys are live savers.

    Reply
  27. Kumaar Dev Sharma says:
    Oct 26, 2017 at 11:39 am

    this is very helpful to me….very nice post

    Reply

Leave a Reply Cancel reply

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

Over 1,320,000+ Readers

Get fresh content from WPBeginner

Featured WordPress Plugin
WP Mail SMTP logo
WP Mail SMTP
Fix WordPress email delivery issues. #1 SMTP plugin. Learn More »
How to Start a Blog How to Start a Blog
I need help with ...
Starting a
Blog
WordPress
Performance
WordPress
Security
WordPress
SEO
WordPress
Errors
Building an
Online Store
Useful WordPress Guides
    • 7 Best WordPress Backup Plugins Compared (Pros and Cons)
    • How to Fix the Error Establishing a Database Connection in WordPress
    • Why You Need a CDN for your WordPress Blog? [Infographic]
    • 30 Legit Ways to Make Money Online Blogging with WordPress
    • Self Hosted WordPress.org vs. Free WordPress.com [Infograph]
    • Free Recording: WordPress Workshop for Beginners
    • 24 Must Have WordPress Plugins for Business Websites
    • How to Properly Move Your Blog from WordPress.com to WordPress.org
    • 5 Best Contact Form Plugins for WordPress Compared
    • Which is the Best WordPress Popup Plugin? (Comparison)
    • Best WooCommerce Hosting in 2020 (Comparison)
    • How to Fix the Internal Server Error in WordPress
    • How to Install WordPress - Complete WordPress Installation Tutorial
    • Why You Should Start Building an Email List Right Away
    • How to Properly Move WordPress to a New Domain Without Losing SEO
    • How to Choose the Best WordPress Hosting for Your Website
    • How to Choose the Best Blogging Platform (Comparison)
    • WordPress Tutorials - 200+ Step by Step WordPress Tutorials
    • 5 Best WordPress Ecommerce Plugins Compared
    • 5 Best WordPress Membership Plugins (Compared)
    • 7 Best Email Marketing Services for Small Business (2020)
    • How to Choose the Best Domain Registrar (Compared)
    • The Truth About Shared WordPress Web Hosting
    • When Do You Really Need Managed WordPress Hosting?
    • 5 Best Drag and Drop WordPress Page Builders Compared
    • How to Switch from Blogger to WordPress without Losing Google Rankings
    • How to Properly Switch From Wix to WordPress (Step by Step)
    • How to Properly Move from Weebly to WordPress (Step by Step)
    • Do You Really Need a VPS? Best WordPress VPS Hosting Compared
    • How to Properly Move from Squarespace to WordPress
    • How to Register a Domain Name (+ tip to get it for FREE)
    • HostGator Review - An Honest Look at Speed & Uptime (2020)
    • SiteGround Reviews from 4196 Users & Our Experts (2020)
    • Bluehost Review from Real Users + Performance Stats (2020)
    • How Much Does It Really Cost to Build a WordPress Website?
    • How to Create an Email Newsletter the RIGHT WAY (Step by Step)
    • Free Business Name Generator (A.I Powered)
    • How to Create a Free Business Email Address in 5 Minutes (Step by Step)
    • How to Install Google Analytics in WordPress for Beginners
    • How to Move WordPress to a New Host or Server With No Downtime
    • Why is WordPress Free? What are the Costs? What is the Catch?
    • How to Make a Website in 2020 – Step by Step Guide
Deals & Coupons (view all)
MainWP
MainWP Coupon
Get 15% OFF on MainWP WordPress multisite manager plugin.
Sprout Invoices
Sprout Invoices Coupon
Get 50% OFF on Sprout Invoices WordPress invoicing plugin.
Featured In
About WPBeginner®

WPBeginner is a free WordPress resource site for Beginners. WPBeginner was founded in July 2009 by Syed Balkhi. The main goal of this site is to provide quality tips, tricks, hacks, and other WordPress resources that allows WordPress beginners to improve their site(s).
Join our team: We are Hiring!

Site Links
  • About Us
  • Contact Us
  • FTC Disclosure
  • Privacy Policy
  • Terms of Service
  • Free Blog Setup
  • Free Business Tools
Our Sites
  • OptinMonster
  • MonsterInsights
  • WPForms
  • SeedProd
  • Nameboy
  • RafflePress
  • Smash Balloon

Copyright © 2009 - 2021 WPBeginner LLC. All Rights Reserved. WPBeginner® is a registered trademark.

Managed by Awesome Motive | WordPress hosting by SiteGround | WordPress CDN by MaxCDN | WordPress Security by Sucuri.