1

My friend has come to me today to tell me he wants his wordpress site moved from example.com to example2.com.

I have full access to the same server managing both those URLs, I copied the entire file and folder contents that apply to example.com over to example2.com so that both domains are 100% duplicate.

When I tried accessing everything on example.com, everything works. However, when I tried accessing the wordpress pages on example2.com, I get redirected to example.com but the rest of the URL is the same.

I checked .htaccess in example2.com as well as the server httpd.conf files and nothing there shows any signs of redirect. However, when I modified a PHP file (so that all it does is print a word instead of loading all the wordpress stuff), there are no redirects and the word is displayed. So this suggests to me that something in wordpress is causing the redirects.

I suggested to my friend to login to wordpress and enter some settings section to change the base domain of the site from example.com to example2.com but I believe he does not know how to do that.

Another possibility is that I find some sort of configuration file or database entry that points to the domain or some setting in relation to it?

As a last resort, I could delete all the work my friend put into his wordpress site and do a clean re-install but I don't think he would appreciate that.

So what would be the best course of action? and if I go about changing settings, what database fields or files should I change so that anything wordpress related that is requested on example2.com doesn't get redirected to the same resource on example.com?

2 Answers 2

2

The answer by Stephen's Ostermiller ♦ is correct but sometimes you can run into problems even when updating the site address, this is due to the fact that plugins don't always update their paths when changing the site address, which means you need to scan through the SQL and make further changes.

Personally, I use phpMyAdmin to export the database from the old domain and then use 'notepad' to open the database and do a search and replace on https://example-old.com to https://example-new.com/.

You should also do a search and replace on local file system paths, for example, you should change all entries of the database from /home/example-old.com/public_html/ to /home/example-new.com/public_html/, but it should be noted that your paths may be different, some hosting hosts the public_html in /var/ some use /httpdocs/ instead of /public_html/ and so on. A detailed answer linked below which should help.

SOURCE

Unless your using a SEO plugin that controls the SEF URLS then there is only several ways that WordPress will redirect, these are: SQL, .HTACCESS and WP-CONFIG.PHP

WP-CONFIG

Unlike older versions of Joomla and other other content management systems by default WordPress does not set the URL path, unless you edit this file and change the defined path. The define untouched looks like:

if ( !defined('ABSPATH') )
  define('ABSPATH', dirname(__FILE__) . '/');

HTACCESS

WordPress by default does not control the install path using the htaccess file, a default htaccess should look exactly like this:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

SQL

WordPress by default on install will add two entries into your SQL database:

  • wp-options
    • option_name: siteurl option_value: http://www.example.com
    • option_name: home option_value: http://www.example.com

You shouldn't need to edit the database directly, as WordPress allows you to change the siteurl, and home path directly in your WordPress.

  • Navigate to http://www.example.com/wordpress/wp-login.php
  • Login to the administration dashboard
  • Click Settings
  • Click General
  • Change WordPress Address (URL)
  • Change Site Address (URL)
  • Click Save

Your settings should look something like this:

WordPress General Settings

If for whatever reason you can't login then use phpMyAdmin to change the values outside of the WordPress environment.

2
  • I'll tell my friend to login again. I could probably pull off PhpMyAdmin but If I could somehow do it the direct mysql way from within shell, that would be better for me, rather than the song-and-dance of logging into Cpanel and PHPmyadmin. Commented Sep 25, 2018 at 23:52
  • Ok, he did get it to work after all. Commented Sep 26, 2018 at 0:14
1

WordPress configuration has a "Site URL" that it uses to redirect to alternate domains to the main domain. You just need to change the site URL.

The easiest way to do this is to point both domains to the same virtual host. Then instead of copying the code and site content, you simply visit /wp-admin and change the URL under Settings -> General in two places. Both the "WordPress Address" and "Site Address":

WordPress Site URL

When you have copied the site, you have to change these settings in a configuration file instead. You can't access wp-admin on the copied site because you get redirected away from it. Here is WordPress documentation for changing the site URL. Edit wp-config.php and add two lines:

define('WP_HOME','http://example2.com');
define('WP_SITEURL','http://example2.com');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.