大网数据广告活动
网站运营与故障问答

Redirect subdomain http:// to https:// - too many redirects

· 52CE 我爱测

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 l…

问题原文

原帖链接 · 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.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Webmasters Stack Exchange
适用范围
以原帖系统、软件版本与发布日期为准(2016-06-05)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。