• I have taken over management of a WordPress site which I didn’t develop, actually having no prior experience with WordPress, although I’m very familiar with web applications in general (primarily a Java developer) and am comfortable with server management. I successfully migrated this site to a new server where it is running well.

    I am now trying to set up a copy of the site for testing purposes on a different server, and have copied across the directory and database set up Apache, etc. with virtual host, and changed the site URL etc. in the options table. A straight PHP page is served fine but with anything handled by WordPress, such as the start page, I’m getting a redirect loop – the Apache access log shows repeated ‘GET /’ – until the browser gives up.

    I’m trying to work out what the difference could be between this copy and the working original site and would appreciate any suggestions as to where to look. The server architecture is a little different from the original site but I can’t think why this might be a problem. Because I also have nginx running on this server, I have configured Apache to run on a different port (8040), with nginx acting as a reverse proxy in front of it (all requests which are not to /api are proxied to Apache). So, let’s say the URL is ‘https://staging.mysite.com/‘. This is handled by nginx and the request is proxied (forwarded) to Apache at ‘https://127.0.0.1:8040‘. The site URL etc in WordPress (as configured in wp-config.php and or directly in the database) is ‘https://staging.mysite.com/‘.

    It’s not superintuitive but it works, and given that a simple ‘info.php’ page in my site directory works fine, clearly the proxying is working as it should. It’s just that an actual WordPress page causes a redirect which then becomes an infinite loop. Any suggestions as to why this might be?

    • This topic was modified 2 years, 1 month ago by johnny2r.
    • This topic was modified 2 years, 1 month ago by johnny2r.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator bcworkz

    (@bcworkz)

    WP has a canonical redirect feature. It’ll automatically redirect non-canonical requests to the canonical URL. The canonical domain is likely staging. Which you redirect to port 8040. Then WP redirects back to staging, which is redirected to port 8040. Which is… you get the idea.

    You probably need to prevent canonical redirects for port 8040 requests. This can be done through the ‘redirect_canonical’ filter. Returning false prevents canonical redirects.

    Thread Starter johnny2r

    (@johnny2r)

    Thanks, but sadly this didn’t help (unless I’m not doing it right). I didn’t expect it to, though, because what the proxy is doing is not redirecting so much as rewriting. It is passing on the https://staging.mysite.com/ as the Host header, so as far as the virtual host is concerned, it is has no knowledge that it is not the receiving server – the proxying is invisible to it.

    Moderator bcworkz

    (@bcworkz)

    ‘redirect_canonical’ is the only “normal” redirect within WP that I know of. If that has been disabled and you still get an infinite loop, I suspect the cause is external to WP. Perhaps try configuring a trace for the access log? Perhaps that’ll give you a better idea on the cause of the looping.

    Thread Starter johnny2r

    (@johnny2r)

    The answer to this, the key difference between the two systems, turned out to be to do with the use of the nginx reverse proxy. There were some extra settings required in ‘wp-config.php’, as delineated here: https://blog.ldev.app/running-wordpress-behind-ssl-and-nginx-reverse-proxy/. I haven’t looked into why these were required for my migrated site but not for the original, which is also sitting behind a nginx reverse proxy, but it may well be to do with the fact that in the original, the WP site is on a different host, accessed via https whereas in the copy it’s under the same host, accessed via http on port 8040. I imagine that the issue is possibly to do with http -> https redirection.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Too many redirects after migrating site’ is closed to new replies.