How to transfer a WordPress website from a subdomain to the main domain when the WordPress website is on a subdomain but now, for whatever reason you decide to transfer WordPress to the main domain of the website. This is usually the case on personalized websites that design the main domain with a simple HTML page so that they merely write social networking and some brief descriptions of their own in the main domain, but wherever they intend to have WordPress on the subdomain or Sub-folder launches. After some time, they decide to highlight the main domain with the same WordPress theme and show details about it themselves, along with the portfolio and everything else in a section.
In this tutorial from the Kiuloper base, I plan to translate WordPress from the subdomain to the main domain, using this tutorial, you can migrate your WordPress website, which is on a subdomain, to the main domain of the site. So if you also decide to move all the details of your website, which is already on the subdomain, to the main domain, read until the end of this article.
The transfer of WordPress from one host to another host will include the following:
- Extract WordPress Files
- Transfer files to routers
- Update and correct the domain address so that all the addresses on the subdomain were changed to the main domain.
- Transfer and redirection of users from the subdomain to the main domain (optional)
Before anything, please backup your website!
Now that you have backed up your website and hosting, you can move your WordPress from the subdomain to the main domain after completing the four steps. Note that all these steps should be carefully performed.
Step 1: Export and transfer WordPress files
The first thing to do is provide an output file from the files in the file manager. So, to get the output from WordPress files, you first need to login to your administrator’s cPanel to an then create the output version of all WordPress files in a ZIP format. First login by going to your website.domain/cpanel. Then, on the login screen, enter the username and password fields of the information that you provided when purchasing the hosting. Then, if your host is cPanel, then click on the File Manager option in the Files section below to navigate to the File Manager page in the cPanel Host.
After logging in to the hosting page, visit the public_html path for your website’s files. In this path there is a folder that is related to your sub domain and WordPress files are in this folder. If you know which files are inside the folder, go directly to the corresponding folder and then Select All Files and WordPress Folders. Right after selecting WordPress files and folders, right-click on them and select the Compress option for output.
After clicking on the Compress option, the following window will appear to you in which you must first select the output file format in ZIP mode, and then at the end of the window, enter the path to save the file with the title.
Format the file you want to output on the zip. Then put the output file with the desired name. Finally, click on the Compress Files button and wait for the output file to be delivered depending on the size of the site data.
Step 2: Transfer WordPress files to your root
Now, after you’ve created your output file, right-click the file and select the move option. Then the path you need to transfer the file will show that by removing the name of the subdirectory you can transfer it to public_html.
Right-click on the file, and then click the extract the files from the compressed state.
So far, we have put WordPress files correctly and in the public_html web host, and in the next step, we need to modify the routing that applies to WordPress URLs.
Step 3: Update the domain URL in the WordPress database
In this step, we need to correct the website links. Because all WordPress links are on the subdomain, but now we need to change everything to the main domain.
Enter the phpMyAdmin host and select the wp-options table for the WordPress database. Depending on the name you chose, go to this tile, and then find the website url and home records in the table records that are displayed, and replace the domain name of your website.
To do this, just click the Edit button, which is similar to the image above. Then, in the edit page, enter the domain name instead of the subdomain address.
Once you have set the domain name for your website, you should also update the internal WordPress links so that all the links on the website are set up based on the domain name. To do this, click the name of the website’s database inside phpmyadmin, then open the SQL header and type the code in it.
UPDATE wp_posts SET post_content = REPLACE (post_content, 'subdomain.domain.com', 'domain.com/');
Instead of subdomain.domain.com in the above code, put your subdomain and instead of domian.com your main domain. and simply put this in the Run SQL query/queries on database field and finally click on the Go button and wait for the update to take place. After this, your website will be successfully loaded on the host and domain. Now you have to check and see if WordPress is right on the main domain. If you have completed all the steps correctly, WordPress is properly migrated from the subdomain to the main domain.
Step 4: WordPress 301 redirects from subdomains to the main domain
Doing this is completely optional and depends on your circumstances. If you have a lot of links to your WordPress website and Google’s index, you should do this so that all points are recorded for the new domain. But if the previous site has just been launched and there is not much information on it, you will not need to do this. So, you need to be able to completely transfer the website from the subdomain to the domain in WordPress 301 redirects. As always, using the plugin can be the easiest thing for you.
But the story does not just end here, and you have to do things to introduce WordPress to Google. Finally, by doing this, WordPress is properly transferred from the subdomain to the main domain and now you can manage and develop your own website with your new and custom address.