apache - 强制使用主域和 www.但不是子域

标签 apache .htaccess mod-rewrite ssl

我安装了域和 SSL 证书。它不是通配符 SSL。

我们为托管在他们服务上的其中一个子域进行了第三方 url 重写 - 这是我无法摆脱或控制的。

他们在子域上没有 SSL。现在我已经安装了 SSL,子域也总是重定向到 https,这会引发错误。

我希望子域转到 http 而主域只转到 https。

我的 htaccess 中最初有以下内容:

RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

我已经删除了它,所有内容仍然指向 https。

最佳答案

We have a third-party url rewrite for one of the subdomains that is hosted on their services

这是在您的 .htaccess 文件之外进行的操作吗?这个第 3 方重写可能会导致问题。

但是,如果您只想忽略子域,只需将其添加到规则即可。

RewriteEngine on
RewriteCond %{HTTPS} !^on
RewriteCond %{HTTP_HOST} !^subdomain\.example\.com [NC]
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

关于apache - 强制使用主域和 www.但不是子域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29433830/

相关文章:

apache - 安装 LetsEncrypt 证书后 VirtualHost 导致 ERR_TOO_MANY_REDIRECTS

apache - https htaccess 排除一些 url

.htaccess - 强制www。和 SSL,无需选择端口

.htaccess - 如何将这个异常添加到htaccess中?

php - Mod_Rewrite 规则冲突让我发疯

regex - 带有通配符和问号的 Apache Rewrite 问题

url - 如何改进 URL 的结构

php - 重定向 POST htaccess

php - 如何将 HTTP header /正文与 PHP 套接字请求隔离开来

apache - 帮助理解mod_rewrite