Redirect loop on server for no apparent reason

Posted June 22, 2016 2.8k views

Hi all,

I have a droplet that seems to be stuck in a redirect loop for no apparent reason. My client wanted all traffic to point to a www address rather than the non www address which was fine until I tried to do the redirect using my apache config.

Redirect permanent /

After adding that line to the config and reloading apache it made the page return a redirect loop. I promptly removed this from the file and restarted apache but still a loop appears. I delved further into the problem and found these lines in my .htaccess file:

<IfModule mod_rewrite.c>
    RewriteCond %{HTTPS} !=on
    RewriteCond %{HTTP_HOST} !^www\. [NC]
    RewriteCond %{SERVER_ADDR} !=
    RewriteCond %{SERVER_ADDR} !=::1
    RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

I also removed these from the file and still there was a loop. I created a new htaccess file that doesnt contain these lines at all and still there is a loop. I cannot see any configuration anywhere that will be causing a redirect. Is there anywhere I can look on the server to find more information about it or something I am missing that jumps out to anyone. The site in question is just hand built php so not running on wordpress or any kind of CMS.

It was setup before I started working on it so there may be things that I have missed but I know that it is running PHP5-FPM and Apache2.

Any help or advice would be greatly appreciated.


1 comment
  • A quick note: I have spoken with the dns providers and they have assured me that everything on their end is correct and there should be no loops there.

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
1 answer

As stupid as this sounds I found the culprit.

This server was set up before I worked on the site and the person who set it up failed to mention that varnish was installed on the server so it turns out that varnish was caching a broken version of the site.

simply stopping and starting varnish has solved the problem. (hopefully)