.htaccess - 多个 url 托管只有一个需要 https

标签 .htaccess ssl https multiple-sites

我在一台服务器上有多个站点,但其中一个 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/

相关文章:

url - Tomcat session 管理——url重写和从http切换到https

javascript - Express (node.js) 使用 HTTPS 和 HTTP

java - 使用 Heroku 上的 Ninja 框架将 HTTP 重定向到 HTTPS

PHP CURL 和 SSL 证书(或证书链)

python - 让 python 应用程序访问存储在 Windows 证书管理器中的证书

Java HttpsURLConnection SSLHandshakeException

php - 上传表单 - 无法上传/发布超过 120 Kb

.htaccess 中的正则表达式 - 如果在 HTTP_HOST 中找到一个 uri,我该如何 301?

php - 禁用服务器日志文件wordpress中的所有php警告

html - 尽管 IE,@font-face 在 Chrome 和 FireFox 中不工作