Migration failed badly - Redirect loop error (server)

June 18, 2014 10k views
Hi guys, I followed this guide in migrating WordPress (https://www.digitalocean.com/community/tutorials/how-to-migrate-wordpress-from-shared-hosting-to-a-cloud-server-with-zero-downtime) and everything went okay UNTIL the last part. After changing DNS and IP, I keep receiving error server redirect loop error. I tested with various browser and even clear cache, but still doesn't work. I am using www by the way. I'm out of ideas on where this problem lies. Do you mind to share your thoughts? Using Unbuntu 14.04 & LAMP. Thanks!
6 Answers
For starters, I found this:
curl reginaldchan.net -vvv
* About to connect() to reginaldchan.net port 80 (#0)
*   Trying connected
* Connected to reginaldchan.net ( port 80 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/ zlib/1.2.3 libidn/1.18 libssh2/1.4.2
> Host: reginaldchan.net
> Accept: */*
< HTTP/1.1 301 Moved Permanently
< Date: Wed, 18 Jun 2014 15:55:54 GMT
< Server: Apache/2.4.7 (Ubuntu)
< X-Powered-By: PHP/5.5.9-1ubuntu4
< X-Pingback: http://www.reginaldchan.net/xmlrpc.php
< Location: http://www.reginaldchan.net/
< Content-Length: 0
< Content-Type: text/html; charset=UTF-8
* Connection #0 to host reginaldchan.net left intact
* Closing connection #0
Now, when I do a nslookup on www.reginaldchan.net, I get this:
nslookup www.reginaldchan.net

** server can't find www.reginaldchan.net: NXDOMAIN
It looks like when you set up DNS, you forgot to add the www CNAME to point to reginaldchan.net Now, when I curl it and force the server, here's what I get:
curl -H "host: www.reginaldchan.net"

<title>301 Moved Permanently</title>
<h1>Moved Permanently</h1>
<p>The document has moved <a href="http://www.reginaldchan.net/">here</a>.</p>
<address>Apache/2.4.7 (Ubuntu) Server at www.reginaldchan.net Port 80</address>
Now, this tells me that your server is saying "I'm reginaldchan.net. You're wanting www.reginaldchan.net." Then the browser tries to go to www.reginaldchan.net, and it says "I'm reginaldchan.net. You're wanting www.reginaldchan.net..." ad infintum. Edit /etc/sites-enabled/(WHATEVER CONFIG YOU'RE USING) and add this line after <VirtualHost *:80> or <VirtualHost _default_:80>:
ServerName reginaldchan.net
Server Alias www.reginaldchan.net
save the file, and run this:
service apache2 reload
  • Hey! Thanks for coming back. Really appreciate it. I am using this:
    <VirtualHost *:80>
         ServerName yourdomain.com
         DocumentRoot /var/www/
    <VirtualHost *:80>
         ServerName www.yourdomain.com
         Redirect permanent / http://yourdomain.com/
    Do I add the lines into both spots or just either one? Sorry! Just want to clarify :)
  • Had exactly this problem, your tips are spot on, helped me fix it quickly, thank you!

When you say "guys", I'm assuming you mean DO guys. I'm a customer, but this might help: are you familar with the database? If so, you might want to check if in the wp_options (or SOMETHING_options) table you don't have the siteurl set to the old IP:
select * from wp_options where option_name='siteurl'

| option_id | option_name | option_value             | autoload |
|         1 | siteurl     | http://YOUR_DOMAIN | yes      |
if it has an IP rather than a domain, run this:
UPDATE wp_options SET option_value='http://YOUR_DOMAIN' WHERE option_name='siteurl';
change YOUR_DOMAIN to your actual domain, of course. Also, you might want to make sure you ported over the .htaccess file. If you did, you will need to make sure AllowOverride is set to ALL in the Apache config.
  • Hi jon, Thanks for the reply. Just checked. Seems like mysql is okay. Here's the site: http://www.reginaldchan.net The error I receive: The webpage at http://www.reginaldchan.net/ has resulted in too many redirects. Clearing your cookies for this site or allowing third-party cookies may fix the problem. If not, it is possibly a server configuration issue and not a problem with your computer. Learn more about this problem. Error code: ERR_TOO_MANY_REDIRECTS Hmm! I'm so lost now :/
Replace all that with this (remove any spaces before > and after < ):
ServerName yourdomain.com 
ServerAlias www.yourdomain.com
DocumentRoot /var/www/
<Directory / >
AllowOverride All
  • Hi jon, Let me see if I get this right. I change the whole thing into the codes you provided right? When this is done, it says VirtualHost error. Hmm... *again, sorry for disturbing!*
  • If you're still having issues, hit me up at jonsjava.com
Here's a vhost config for you: http://curltools.com/vhost.conf You can replace the ones you have with this one.
  • Hi jon, Seriously, you really have patience with a newbie like me :) Thanks for the config. Now, I have added it up and no more redirect loop. However, a check on the site on a fresh browser shows empty white page. Database issue maybe? *Temporary, I have just reuse my old DNS back as I need to grab a quick nap. It's 2am and been trying to resolve this over 7 hours now. So, back in a few hours. Mean time, I am thinking the problem could lie in: 1. database 2. wp files Am I on the right track? Thanks! Talk to you soon.
  • Everybody starts off a newbie. Never known someone born with an RHCE.
easy solution:
tail -20 /var/log/apache2/reginaldchan.net-error.log
It will tell you what's wrong.
  • Hi jon, I'm back :) Now, the log is empty and thus, I believe no error is logged here (size also shows 0 kb). Google keep showing a blank page so, I have no idea what went wrong. Any suggestions on this? *Temporary, I'm redownloading & reuploading my wp files and as well as mysql. Just in case... **Edit: I have Site Sensor and it shows Socket Error. Not sure what this means and not sure if this info helps. Thanks!
The domain I told you to contact me at. It's Jon at that domain. shoot me an e-mail.
Have another answer? Share your knowledge.