the "Too many redirects" issue comes from the fact that redirects are tied together. For example, http://example.com redirects to https://example.com and https://example.com redirects back to http://example.com.
This process can repeat itself over and over again until the redirect count established by the server is reached, then when that is exceeded, the server then stops trying to process redirects.
In apache, this can be discovered by seeing the "this page can be found here" message on the screen (which is an actual redirect page) instead of the behind-the-scenes automatic redirect that the browser processes.
What I would suggest you do when testing your scripts is to make them non-cacheable to get current results every time. You should also check to ensure the user requests the HTTPS version of the site, and only perform the redirect if the request isn't HTTPS. One way to check is to validate the server port number the user connects to and if the port number is 80 then make the redirect happen for the user since port 80 is HTTP.
Another thing helpful is to turn off automatic redirects in your browser while testing your pages.
If that is not possible, use redbot.org and put your URL that is causing problems in it then you'll see what the new URL is under "Location:" in the HTTP headers. Keep following the URL until you no longer see the "Location:" value. If you can't then you have an endless redirect.