简体   繁体   English

特定域的htaccess force ssl

[英]htaccess force ssl for a particular domain

How do I force SSL for a particular domain currently I have 我如何为当前拥有的特定域强制使用SSL

RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

This is working, however I have several add on domains on my hosting and when I try to access the other add-on domains, the add-on domains are also forced to use SSL. 这是可行的,但是我的主机上有多个附加域,当我尝试访问其他附加域时,附加域也被迫使用SSL。

I tried this: 我尝试了这个:

RewriteCond %{HTTP_HOST} ^exampledomain\.org$ [OR]
RewriteCond %{HTTP_HOST} ^www\.exampledomain\.org$
RewriteRule ^/?$ "https\:\/\/www\.examplemydomain\.org\/" [R=301,L]

But it is giving me an infinite loop. 但这给了我无限循环。

This should work: 这应该工作:

RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} exampledomain\.org$ [NC]
RewriteRule ^ https://www.examplemydomain.org%{REQUEST_URI}  [R=301,L,NE]

It looks like you're doing 2 different things here. 看来您在这里做2件事。 You're adding a www when one is missing, and you're forcing SSL when it isn't used. 当缺少一个www时,您将添加一个www ;而当不使用它时,您将强制使用SSL。 So there's 2 different conditions and either one being true should force a redirect. 因此,存在两种不同的条件,任何一个条件成立都应强制重定向。 That means you want to use the [OR] flag, but the way you were using it breaks if the request is already SSL . 这意味着您想使用[OR]标志,但是如果请求已经是SSL,则使用它的方式就会中断。 Try: 尝试:

RewriteCond %{HTTP_HOST} ^exampledomain\.org$ [OR]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://www.examplemydomain.org/$1 [R=301,L]

try: 尝试:

RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(www\.){0,1}exampledomain\.org$
RewriteRule ^/?$ "https\:\/\/www\.examplemydomain\.org\/" [R=301,L]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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