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

时间:2015-02-06 17:06:12

标签: apache .htaccess mod-rewrite

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

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

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

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

接下来我希望任何点击subdomain.domain.com或domain.com/subdomainname的人重定向到https://subdomain.domain.com,所以我在subdomain文件夹中的.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]

关于我做错了什么的暗示?

1 个答案:

答案 0 :(得分:0)

用此替换您的子域名.htaccess:

RewriteEngine On

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