How to Change Your WordPress Site URLs (Step by Step)

1 week ago, WordPress Tutorials, 2 Views
How to change your WordPress site URLs (step by step)

Understanding WordPress URLs

Before diving into the process of changing your WordPress site URLs, it’s crucial to understand the different types of URLs involved and the implications of making these changes. Two primary URLs are central to your WordPress installation:

  • **WordPress Address (URL):** This is the URL where your WordPress core files are located. It’s the address you type into your browser to access the WordPress administration panel (wp-admin).
  • **Site Address (URL):** This is the URL that visitors see when they access your website. It’s the address that appears in the address bar of their browser.

In many cases, these two URLs are the same. For instance, both could be `https://example.com`. However, there are scenarios where they might differ. A common example is when you have WordPress installed in a subdirectory. In such a case, your WordPress Address might be `https://example.com/wordpress`, while your Site Address remains `https://example.com`.

Changing these URLs can have significant consequences if not done correctly. It can lead to broken links, inaccessible content, and even a completely broken website. Therefore, it’s imperative to follow the steps carefully and back up your site before making any changes.

Reasons for Changing Your WordPress URLs

There are several legitimate reasons why you might need to change your WordPress URLs:

  • **Migrating to a New Domain:** This is perhaps the most common reason. You might be rebranding your business or simply want a more memorable domain name.
  • **Moving WordPress to a Subdirectory or Vice Versa:** As mentioned earlier, you might want to move your WordPress installation from the root directory to a subdirectory (e.g., `https://example.com/blog`) or vice versa.
  • **Switching from HTTP to HTTPS (SSL Certificate Installation):** If you’ve installed an SSL certificate, you’ll need to update your URLs to use `https://` instead of `http://`.
  • **Changing from www to Non-www (or Vice Versa):** You might prefer to use `www.example.com` instead of `example.com`, or vice versa. This is primarily a matter of preference and SEO best practices.

Regardless of the reason, the process remains fundamentally the same, although some specific steps might require slight adjustments depending on your situation.

Preparation: Backing Up Your WordPress Site

Before making any significant changes to your WordPress site, including URL changes, it’s absolutely essential to create a complete backup. This backup will serve as a safety net, allowing you to restore your site to its previous state if anything goes wrong during the URL modification process.

A comprehensive backup should include:

  • **WordPress Files:** This includes all the core WordPress files, themes, plugins, and any other files you’ve uploaded to your WordPress installation directory.
  • **WordPress Database:** This contains all your posts, pages, comments, user data, settings, and other critical information.

There are several ways to back up your WordPress site:

  • **Using a WordPress Backup Plugin:** Numerous plugins like UpdraftPlus, BackupBuddy, and BlogVault can automate the backup process. They typically allow you to schedule regular backups and store them in a safe location, such as cloud storage.
  • **Manual Backup:** You can manually back up your WordPress files by downloading them via FTP or a file manager provided by your hosting provider. You can back up your database using phpMyAdmin, which is often accessible through your hosting control panel. Export the database as a `.sql` file.
  • **Hosting Provider’s Backup Service:** Many hosting providers offer their own backup services. Check with your hosting provider to see if they offer this option and how to utilize it.

Once you have a complete backup, store it in a secure location, preferably off-site, such as a cloud storage service or an external hard drive.

Method 1: Changing URLs Through the WordPress Admin Dashboard

This is the easiest and most straightforward method for changing your WordPress URLs, assuming you have access to the WordPress admin dashboard.

**Steps:**

1. **Log in to your WordPress Admin Dashboard:** Access your WordPress admin panel by navigating to `yourdomain.com/wp-admin` (replace `yourdomain.com` with your actual domain).

2. **Navigate to Settings > General:** In the left-hand menu, find the “Settings” option and click on “General.”

3. **Locate the WordPress Address (URL) and Site Address (URL) fields:** On the General Settings page, you’ll find two fields labeled “WordPress Address (URL)” and “Site Address (URL).”

4. **Enter the New URLs:** Carefully enter the new URLs you want to use in the corresponding fields. Double-check for typos before proceeding.

5. **Save Changes:** Scroll to the bottom of the page and click the “Save Changes” button.

**Important Considerations:**

* **Potential Login Issues:** After saving the changes, you might be automatically logged out and unable to log back in. This is because your login cookies are associated with the old URL. To resolve this, you may need to clear your browser’s cache and cookies or use Method 2 or 3.
* **HTTPS Redirects:** If you’re switching to HTTPS, ensure you have properly configured HTTPS redirects in your `.htaccess` file (or through your hosting provider’s control panel). This will automatically redirect visitors from the HTTP version of your site to the HTTPS version.

Method 2: Changing URLs Using wp-config.php

If you’re locked out of your WordPress admin dashboard, you can change your URLs by modifying the `wp-config.php` file. This file contains important configuration settings for your WordPress installation.

**Steps:**

1. **Access Your Server:** Use an FTP client (like FileZilla) or a file manager provided by your hosting provider to access your server.

2. **Locate the `wp-config.php` file:** The `wp-config.php` file is located in the root directory of your WordPress installation.

3. **Download the `wp-config.php` file:** Download a copy of the file to your computer as a backup.

4. **Edit the `wp-config.php` file:** Open the file in a text editor (like Notepad++, Sublime Text, or VS Code).

5. **Add the following lines of code:** Add these lines *before* the line that says `/* That’s all, stop editing! Happy publishing. */`:

“`php
define( ‘WP_HOME’, ‘https://example.com’ );
define( ‘WP_SITEURL’, ‘https://example.com’ );
“`

Replace `https://example.com` with your new URLs. Make sure to use the correct protocol (HTTP or HTTPS).

6. **Save the Changes:** Save the modified `wp-config.php` file.

7. **Upload the `wp-config.php` file:** Upload the updated file back to your server, replacing the original file.

8. **Log in to your WordPress Admin Dashboard:** Try logging in to your WordPress admin panel. You should now be able to access it using the new URLs.

**Important Considerations:**

* **Caution with Editing:** Be extremely careful when editing the `wp-config.php` file. Incorrect modifications can break your website.
* **Remove the Code After Login (Optional):** After successfully logging in and verifying that the URLs are working correctly, you can optionally remove the added lines from the `wp-config.php` file and update the URLs through the WordPress admin dashboard (Method 1). This is generally recommended for better management. If you leave the definitions in `wp-config.php`, the URL settings in the admin dashboard will be disabled.

Method 3: Changing URLs Directly in the Database

This method is more technical and should only be attempted if you’re comfortable working with databases. It involves directly modifying the WordPress database to update the URLs.

**Steps:**

1. **Access phpMyAdmin:** Log in to your hosting control panel and find phpMyAdmin. This is a tool for managing MySQL databases.

2. **Select Your WordPress Database:** In phpMyAdmin, select the database associated with your WordPress installation.

3. **Find the `wp_options` Table:** Look for the `wp_options` table in the list of tables. The prefix `wp_` might be different depending on your WordPress installation.

4. **Edit the `siteurl` and `home` Options:**
* Click on the “Browse” tab to view the data in the `wp_options` table.
* Find the rows where `option_name` is `siteurl` and `home`.
* Click the “Edit” button next to each of these rows.
* In the `option_value` field, enter the new URLs.
* Click the “Go” button to save the changes.

5. **Update GUIDs (Optional, but Recommended):** The GUID (Globally Unique Identifier) is a unique identifier for each post and page. While it’s not strictly necessary to update the GUIDs, it’s generally recommended to do so, especially if you’re migrating to a new domain.

* Go back to the main database view in phpMyAdmin.
* Click on the “SQL” tab.
* Enter the following SQL query (replace `yourdomain.com` with your old domain and `newdomain.com` with your new domain):

“`sql
UPDATE wp_posts SET guid = REPLACE (guid, ‘yourdomain.com’, ‘newdomain.com’);
UPDATE wp_postmeta SET meta_value = REPLACE (meta_value,’yourdomain.com’,’newdomain.com’);
UPDATE wp_options SET option_value = REPLACE (option_value, ‘yourdomain.com’, ‘newdomain.com’) WHERE option_name = ‘widget_%’;
“`
* Click the “Go” button to execute the query. Be aware this query could take a while depending on the size of the database.

**Important Considerations:**

* **Database Knowledge Required:** This method requires a good understanding of database management. Incorrect modifications can corrupt your database and break your website.
* **Backup Before Editing:** Always back up your database before making any changes.
* **Double-Check the Table Prefix:** Ensure you’re using the correct table prefix (e.g., `wp_`, `wp123_`, etc.).
* **SQL Injection:** Be very cautious when entering SQL queries to prevent SQL injection vulnerabilities. Ensure you’re using proper escaping and sanitization techniques.

Post-Change Steps: Updating Internal Links and Permalinks

After successfully changing your WordPress URLs, there are a few post-change steps you should take to ensure your website is functioning correctly and to optimize it for search engines.

  • **Update Internal Links:** Your website likely contains internal links that point to other pages or posts on your site. These links may still be using the old URLs. There are several ways to update these links:
    * **Manual Update:** You can manually edit each page and post and update the links. This is time-consuming but ensures accuracy.
    * **”Search and Replace” Plugin:** Plugins like “Better Search Replace” or “Search & Replace” can automate the process of finding and replacing old URLs with new URLs in your database. Be extremely careful when using these plugins, as they can have unintended consequences if not used correctly. Always create a database backup before using them.
  • **Update Permalinks:** After changing your URLs, it’s a good idea to update your permalinks. This will ensure that your URLs are consistent and SEO-friendly.
    * Go to **Settings > Permalinks** in your WordPress admin dashboard.
    * Choose a permalink structure (e.g., “Post name”).
    * Click “Save Changes.” This will flush your permalink rules and regenerate the `.htaccess` file (if necessary).
  • **Test Your Website:** Thoroughly test your website to ensure that all links are working correctly, images are loading properly, and all pages are accessible.
  • **Update Your Sitemap:** If you use a sitemap plugin (like Yoast SEO or Rank Math), update your sitemap to reflect the new URLs. Submit the updated sitemap to search engines like Google and Bing.
  • **Update Google Analytics and Search Console:** If you use Google Analytics and Google Search Console, update your website URLs in these platforms to ensure accurate tracking and reporting.

Changing your WordPress URLs can be a complex process, but by following these steps carefully and taking the necessary precautions, you can successfully migrate your website to a new domain or update your URLs for other reasons without encountering major issues. Remember to always back up your site before making any changes and to test thoroughly afterward.