我在一台服务器上有多个站点,但其中一个 url 需要是 https。
举个例子: http://www.example1.com/ https://www.example2.com/
我一直在使用 htaccess 来强制使用 https,但它对所有 url 都这样做,基本上破坏了所有 url,除了我有 SSL 证书的那个 url。
我如何在那个网站上强制使用 https?
最佳答案
您可以在 htaccess 中使用双重条件:
- 条件 1:检查 www.example2.com
only
- 条件 2:检查 http
请求仅
RewriteCond %{HTTP_HOST} ^www\.example2\.com$ [NC]
RewriteCond %{HTTPS} =off
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
这样,www.example2.com
中的每个 http
url 都将转到等效的 https
关于.htaccess - 多个 url 托管只有一个需要 https,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25125662/