Apache 在 .htaccess 设置后检测到目标 URL 的外部循环重定向

Apache detected external loop redirection with target URL after .htaccess setup

我已经研究了好几个小时,试图把它弄好。它似乎按照我想要的方式工作,但我收到了这个 Apache 错误。

我想设置它,这样如果有人访问我的主 URL,他们将被定向到 https 和 www,所以我在主 public_html 目录的 htaccess 文件中有这个。

Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.domain.com
RewriteRule ^(.*)$ https://www.domain.com/ [R=301,L]

RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]

接下来我希望任何点击 subdomain.domain.com 或域的人重定向到 https://subdomain.domain.com,所以我在子域文件夹的 .htaccess 文件中有这个。

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
RewriteCond %{HTTP_HOST} ^subdomain\.domain\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.subdomain\.domain\.com$
RewriteRule ^/?$ "https\:\/\/subdomain\.domain\.com\/" [R=301,L]

关于我做错了什么的任何提示?

将您的子域 .htaccess 替换为:

RewriteEngine On

RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !=subdomain.domain.com
RewriteRule ^(.*)$ https://subdomain.domain.com/ [R=302,NE,L]