简体   繁体   English

htaccess将https和www强制为非www,但仅子域https

[英]htaccess force https & www to non-www, but subdomain only https

I have a two websites 我有两个网站

  1. yourdomain.com yourdomain.com
  2. reseller.yourdomain.com reseller.yourdomain.com

Now I want to forcing both domains to use https via apache htaccess redirect. 现在,我想强制两个域通过apache htaccess重定向使用https。 In addition to that, the main domain should use always www instead of non-www. 除此之外,主域应始终使用www而不是非www。 But the subdomain reseller.yourdomain.com shouldn't use www of course. 但是,子域名reseller.yourdomain.com当然不应使用www。

How should the redirect look like? 重定向应如何显示? I have tried so many things like 我尝试了很多类似的事情

RewriteEngine on
RewriteCond %{HTTPS} !^on

RewriteCond %{HTTP_HOST} !^reseller\.yourdomain\.com [NC]

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

This works not 100%, the main domain redirects correctly to www and ssl, the ssl-redirect for the subomdain works only on reseller.yourdomain.com, not on sub-sites like reseller.yourdomain.com/single-page. 这不是100%有效,主域正确地重定向到www和ssl,subomdain的ssl-redirect仅在reseller.yourdomain.com上有效,而在reseller.yourdomain.com/single-page之类的子站点上则无效。

thanks! 谢谢!

Try it like this, 这样尝试

RewriteEngine on
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^yourdomain.com
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301]

RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^(.+)\.yourdomain.com$
RewriteRule ^ https://%1.yourdomain.com [R=301,L]

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

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