简体   繁体   中英

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

I've played around with this for hours, trying to get it right. It seems to be working the way I want, but I'm getting this Apache error.

I want to set it up so if someone visits my main URL they're directed to https and www, so I have this in the htaccess file in the main public_html directory.

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]

Next I want anyone who hits subdomain.domain.com or domain.com/subdomainname to redirect to https://subdomain.domain.com , so I have this in the .htaccess file in the subdomain folder.

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]

Any hints as to what I'm doing wrong?

Replace your subdomain .htaccess by this:

RewriteEngine On

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM