WordPress site redirects to another site

Created:

2017-06-06 23:49:42 UTC

Modified:

2017-08-16 17:35:59 UTC

0

Was this article helpful?


Have more questions?

Submit a request

WordPress site redirects to another site

Applicable to:

  • Plesk for Linux

Symptoms

  • WordPress site example.com redirects to another site (e.g example2.com ).

  • example.com has been restored/migrated from another server's backup.

  • Removing of .htaccess does not help.

In table wp_options inside WordPress database appears siteurl and home with previous/another domain. As following example with oldexample.com:

mysql> SELECT * FROM WP_OPTIONS WHERE option_name = 'siteurl' OR option_name = 'home';
+-----------+-------------+-----------------------+----------+
| option_id | option_name | option_value | autoload |
+-----------+-------------+-----------------------+----------+
| 2 | home | http://oldexample.com | yes |
| 1 | siteurl | http://oldexample.com | yes |
+-----------+-------------+-----------------------+----------+
2 rows in set (0.00 sec)

Cause

Inside WordPress database siteurl and home are pointing to previous/another domain.

Resolution

Update siteurl and home with new domain in your WordPress database with following commands:

mysql>UPDATE `wp_options` SET `option_value` = 'http://example.com' WHERE `wp_options`.`option_id` = 1
mysql>UPDATE `wp_options` SET `option_value` = 'http://example.com' WHERE `wp_options`.`option_id` = 2

For more information, check official WordPress documentation with best practices guide .

OR

  1. Find the name of the database of this WordPress's instance:

    # grep 'DB_NAME' /var/www/vhosts/example.com/httpdocs/wp-config.php
    define( 'DB_NAME', 'wordpress_1' );

    OR

    In Domains > example.com > My CMS > Database name

  2. Create a dump of the WordPress's database:

    # plesk db dump wordpress_1 > /root/wordpress_1.sql
    
  3. Replace example2.com with example.com in the dump:

    # sed -i /root/wordpress_1.sql -e "s/example2.com/example.com/g"  
    
  4. Restore the fixed dump to the database:

    # MYSQL_PWD=`cat /etc/psa/.psa.shadow` mysql -u admin wordpress_1 < /root/wordpress_1.sql 
    
  5. Click Refresh at Domains > example.com > My CMS to update the data in Plesk.

Have more questions? Submit a request
Please sign in to leave a comment.