Raj has a site, he creates a lot of quality content but didn’t have a good amount of traffic. One day he realized that his WordPress URL was pretty long and it didn’t have the site’s name, as a result of which he decides to change it but he wondered how to perform such a daunting task as soon as possible.
Stuck in the same situation as Raj? Don’t worry, In this post, I will teach you how to change WordPress URL easily and it is not as tedious as you think.
To begin with, a WordPress site has two addresses. They are
- Site URL
- WordPress URL
The site URL is where the core files of your site reside. All the wp-config, wp-includes files reside in this location.
The WordPress URL is the address of your site. In other words, it is the address people type in the URL bar to reach your site and it is the one which you typically put down on a business card.
By the way, you might be migrating from a www URL to a non-www URL or you might wish to own a new domain name. Whatever the reason might be this post will guide you step by step on changing the WordPress URL.
WARNING: Messing with the URLs can cause the breakage of the site and even lead to unrecoverable conditions
You can change WordPress URL
- Via Admin dashboard
- Making changes to the wp_config.php file
- Making changes to the Database directly
- Using WP-CLI to change the addresses
- Using the Relocate Flag.
1. Using the Admin Dashboard to change the WordPress URL.
- Firstly, Log on to your site as Admin. Under Dashboard go to Settings>General
2. Over here you can find both the WordPress URL and the site URL. Unless until you are giving WordPress its own directory both the WordPress and site URLs must match. After making the changes, Finally hit “Save Changes”. Do not forget to clear cache.
3. Finally, To clear cache(If you have hosted with site grounds) click on the “Purge SG Cache” option on the top. This clears off the cache data of the site. You further need to clear the cache data of your site. To know how to clear the cache data of your browser, click here.
Through this method you can use the admin dashboard to change the WordPress URL.
2. Changing the site URL by making changes to the wp-config file
- Log on to your Cpanel account in the first place. Click on File Manager. Under the file list, select the one named public.html. It is this file which has all your WordPress database details. It is also known as the web root.
NOTE: In certain cases, you may have to select the public.html file before you can even enter the file manager.
2. In this window, you can find a file named wp-config. Click on it. This is one of the WordPress core files. It contains extremely important info such as the username, database name, password etc…
Moreover this is the file which communicates with the database to store and retrieve data.
3. Enter the following lines of code on the top of the file. If you can already view them, edit them according to your preferences.
NOTE: The example is shown for a non-www file the same applies for a www file. Just add www after https://. Save it.
This is the second method to change the WordPress URL
3. Changing the home and site URL directly from the database using phpMyAdmin
- To begin with, log on to your Cpanel. Under databases, click on phpMyAdmin. This is nothing but a graphical interface for managing the SQL Databases.
2. Then, select the table prefix of the site which you wish to edit. In other words, this is the table which holds the data related to your site. In this case, it is af.
3. Now, click on the “your_table_prefix_name_options”. In this case, it is af_options.
4. Find where the site URL resides. Click on the edit button to edit it. You will be taken to the editing window. Edit the URL based on your preferences and finally hit “Go” in the bottom.
5. Then search for the home URL. If you cannot find it in this page, click on the arrow > near the Page number to move on to the second page where you can find the Home URL.
Click on the “Edit” option to edit it and finally hit “Go” once you are done. It will save the changes to the file.
6. Now close phpMyAdmin and log back on to your site. Do not worry if the changes do not show up. Refresh a few times and finally you can view the site in the new location.
Since you have made changes to the site and home URLs it is probably a good idea to update your permalinks too. To do so,
Log on to your WordPress dashboard. Navigate to Settings>Permalink. Without making any changes finally, Click on “Save Changes” to update your permalinks.
This is one of the five methods by which you can change the WordPress URL.
4. Using WP-CLI to change your wordpress URL
An another method of changing the WordPress URL is by using the WP-CLI.
WP-CLI stands for wordpress command line interface. It is an extremely powerful tool using which you can manage your wordpress site using commands.
If you have no clue about WP- CLI check out this post.
In the CLI type in the following commands to change your home and site URLs. Make sure to type in the site URL which you wish to have within the quotes.
This is method is extremely useful for WordPress developers to change their WordPress URLs.
5. Using RELOCATE flag.
This method is preferred only if you have trouble accessing your WordPress Dashboard. We are going to set the Relocate flag inside the wp-config.php file which automatically helps WordPress to assign the core files to the URL.
- Firstly, log on to your Cpanel to edit the wp-config.php file.
- At the top of the file add the following piece of code
3. Now visit the https://sample.com/wp/wp-login.php. Make sure to type in the path of our wordpress core files before wp-login.php.
4. Finally, log into your WordPress dashboard as always. Navigate to Settings>General. You can find that WordPress has automatically fetched the address of your site.
Frequently asked questions
It means that both the URLs has been hardcoded into the wp-config.php file. Use method 2 to edit them.
Remove the home and site url links from the wp-config file to edit them directly from the dashboard.
Raj has successfully learnt how to change his WordPress URL. He is currently publishing his posts on his site which has a great URL and it has helped him gain a lot of organic traffic. Hope you are benefitted from this post as Raj has. If you have any queries leave them in the comment section below. Until then Sayōnara!