Technical guide on modifying the WordPress Site URL and Home URL directly in the database. Essential for fixing redirection loops and domain migrations on Hovixa VPS.

Altering the WordPress Site URL and Home URL within the wp_options Table

Manually updating the Site URL and Home URL is necessary when you migrate your WordPress instance to a new domain, add an SSL certificate (switching from http to https), or find yourself locked out due to a redirection loop. On a Hovixa VPS, you can execute these changes directly within the wp_options table using the MySQL command-line client.

1. The Difference Between SiteURL and Home

It is analytically important to distinguish these two values to ensure proper routing:

  • siteurl (option_id 1): The physical address where your WordPress core files reside.
  • home (option_id 2): The address you want users to type in their browser to reach your site.

In 90% of installations, these values are identical. They only differ if you are running WordPress in its own subdirectory while serving the site from the root.

2. Locating the Current Values

Access your MySQL shell via SSH and navigate to your database to see the current configuration:

# Access MySQL
mysql -u root -p

# Select database
USE your_database_name;

# Query the URL options
SELECT option_name, option_value FROM wp_options WHERE option_name IN ('siteurl', 'home');
    

3. Executing the Update Query

Run the following queries to update both rows. Ensure you include the protocol (https://) and omit the trailing slash.

UPDATE wp_options SET option_value = 'https://newdomain.com' WHERE option_name = 'siteurl';
UPDATE wp_options SET option_value = 'https://newdomain.com' WHERE option_name = 'home';
    

4. Quick-Reference Table

Requirement Option Name Example Value
Core File Path siteurl https://example.com/wp
Public Facing URL home https://example.com

5. Technical Implementation Details

  • Serialized Data Warning: The siteurl and home options are simple strings, so direct SQL updates are safe. However, do not use direct SQL to replace URLs within the wp_posts or wp_postmeta tables, as those often contain "serialized data" that will break if the string length changes. Use WP-CLI for those tasks.
  • wp-config.php Overrides: If you update the database but the URL doesn't change, check your wp-config.php file. Hardcoded definitions like define('WP_HOME','...') will override the database values.
  • Trailing Slashes: Never include a trailing slash in these fields (e.g., use https://example.com, not https://example.com/). WordPress appends the slash dynamically in its internal routing logic; adding one here can cause double-slash errors in CSS/JS paths.

Sysadmin Advice: If you are performing a full domain migration, changing these two rows is only the first step. You should follow up with **wp search-replace 'old.com' 'new.com'** via WP-CLI to update internal links and image paths across the rest of the database.

Hai trovato utile questa risposta? 0 Utenti hanno trovato utile questa risposta (0 Voti)