问题原文
原帖链接 · Josh N · CC BY-SA 3.0
I'm trying to redirect http://sub.domain.com to https://sub.domain.com.
I have turned the web upside down trying every .htaccess and PHP script out there, and all of them give me the "Too Many Redirects" error.
I'm not so much looking for a solution, as I have pretty much given up on that.
What I'm wondering why I get the error? What does the error actually mean? As far as I can tell, all the scripts I've tried only ever redirect once.
已采纳解答
原帖链接 · Mike -- No longer here · CC BY-SA 3.0
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.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
