0

I downloaded a whole WP install and moved it to a LAMP test environment in order to update it. The original site could be found under example.com, the test site should be under example.com.mytestdomain.com aka {testurl}. In order to achieve that, I created a local DNS record and I changed the site url as well as the home url in the WP dashboard to reflect this test domain.

I can access {testurl}/wp-admin fine, and both the site address as well as the home address are set to {testurl}, and not example.com.

Yet, when I try to access {testurl}, I am always being forwarded to example.com.

I'd be grateful for hints why this could be happening. I have no redirect plugins, (internal) DNS is set up correctly.

Update: In the end, it turned out I did not activate the mod_rewrite module in my httpd.conf which led to my permalinks being ignored on the test server.

After I corrected this mistake, I could correctly access {testurl}/postname but I was still being redirected to example.com when calling {testurl}.

As a next step, I directly called {testurl}/index.php. And this worked. And from that moment on, I can call {testurl} without being redirected.

Frankly, I'm not at all sure about how this last step solved the problem but it's gone now.

11
  • what do you get on ping example.com.mytestdomain.com
    – prosti
    Commented Dec 30, 2016 at 18:10
  • The IP address of my test server.
    – vic
    Commented Dec 30, 2016 at 18:10
  • It is not clear if you are working on your local end, or on some VPS?
    – prosti
    Commented Dec 30, 2016 at 18:13
  • You can set these test domains also locally . This is why?
    – prosti
    Commented Dec 30, 2016 at 18:14
  • what web server?
    – prosti
    Commented Dec 30, 2016 at 18:23

2 Answers 2

2

You may have some problem with JavaScript on your website, with the hardcoded URLs. As I can see you are trying to create the test environment.

This is good, and I like people creating the test environments. You need to go to through your code, JavaScript and PHP to seek for the hardcoded URLs.

Also it is good to have the lines like this in your wp-config.php:

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

I would suggest you do the database export something like

wp db export

If you use wp-cli and after that try to search the export to understand what you have in there. Let us know the feedback.

Anyway, very interesting question. Please feel free to accept this answer if you find it helpful. I think the approach explained in here is really general but you may find it helpful.


From the web server configuration standpoint, try to create a simple index.php in a root of your WordPress that will print "You cannot redirect me!". Let me know the feedback if this will be redirected. ;)

PS: Don't forget to backup the original WordPress's index.php.


So, I think I have a better idea of what is happening. Although the site's address is set correctly to the test site, and even the pages show the correct test site permalinks, all posts still contain, hard coded in the DB, a reference to the original site. Since the site, after calling index.php, immediately opens post number 1, it is being redirected to the original site. Frankly, this is strange, I thought the purpose of the site url and home url is to prevent just that? I will now try changing wp-config.php to see if it has a different effect than setting homeurl and siteurl in the db

You can do something like this once:

update_option( 'siteurl', 'http://example.com.mytestdomain.com' );
update_option( 'home', 'http://example.com.mytestdomain.com' );

After that check what you have in the database when you export it.

Also note, some menu links may be hardcoded in the database, in the options table.

3
  • 1
    So, I think I have a better idea of what is happening. Although the site's address is set correctly to the test site, and even the pages show the correct test site permalinks, all posts still contain, hard coded in the DB, a reference to the original site. Since the site, after calling index.php, immediately opens post number 1, it is being redirected to the original site. Frankly, this is strange, I thought the purpose of the site url and home url is to prevent just that? I will now try changing wp-config.php to see if it has a different effect than setting homeurl and siteurl in the db.
    – vic
    Commented Dec 31, 2016 at 15:22
  • 1
    I can confirm that changing wp-config.php has no additional impact whatsoever over changing siteurl and homeurl in the dashboard.
    – vic
    Commented Dec 31, 2016 at 15:34
  • you are getting there @vic
    – prosti
    Commented Dec 31, 2016 at 16:51
0

You should define both the WP_SITEURL and WP_HOME in your test wp-config.php file, don't forget to remove it when migrating back to the live server.

/**#@-*/
define( 'WP_SITEURL', 'http://example.com.mytestdomain.com' );
define( 'WP_HOME', 'http://example.com.mytestdomain.com' );
3
  • I had to make my question a bit clearer. I already set the site url and home url, not through wp-config.php but directly in the dash board, i.e. in the database. I assume the effect should be the same and yet I'm getting redirected.
    – vic
    Commented Dec 30, 2016 at 17:54
  • You should set in in wp-config.php
    – Tunji
    Commented Dec 30, 2016 at 18:59
  • Also make sure your server config is alright
    – Tunji
    Commented Dec 30, 2016 at 19:04

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.