Learn how to fix wp-admin redirecting to another domain name by updating your wp-config file and WordPress database.
Update WordPress Config File
First step is to edit your wp-config.php file to override the WP_SITEURL and WP_HOME values.
- Open your website’s wp-config.php file in cPanel File Manager or via FTP.
- Add the following lines of code, swapping https://www.example.com with the URL of your home page.
define( 'WP_SITEURL', 'https://www.example.com'); define( 'WP_HOME', 'https://www.example.com');
- Save and publish the file to your web space.
Update WordPress Database
Next step is to update your WordPress database to use the same domain you’ve set in your wp-config.php file.
Update using phpMyAdmin
- Open your WordPress database. Use phpMyAdmin or an app like Sequel Ace.
- Find the table called wp-options.
- Find the option_name called siteurl.
- Change the option_value to match the URL of your home page. eg http://www.example.com
Update using functions.php
If you have FTP access, or access to the File Manager in cPanel, you can update the domain using the following code.
- FTP in to your web space and download a copy the active theme’s functions.php file. The path will be something like /wp-content/themes/mytheme/functions.php.
- Add the following lines of code on a new line immediately after the opening <?php, swapping https://www.example.com with the URL of your home page.
update_option( 'siteurl', 'https://www.example.com'); update_option( 'home', 'https://www.example.com');
- Upload the file back up to your web space, making sure to upload to the same location.
- Open your browser and load your WordPress login screen a couple of times using the domain saved above. eg https://www.example.com/wp-login.php
- Your web site should now load.
- Repeat steps 1 to 3, but this time remove the new lines. For performance reasons it’s important not to leave these lines active on a live website.