.htaccess - 主域为 https,子域为 http

标签 .htaccess http mod-rewrite redirect https

所以我需要非常简单的 .htaccess 代码

我想在没有 WWW 的情况下将所有流量重定向到主域中的 https,并将所有流量重定向到子域中的 http。

现在我正在使用此代码将所有流量重定向到 https

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]

所以主域应该是这样的:https://website.com

子域应该是这样的:http://sub.website.com

我找到了很多答案但很复杂,所以需要简单的解决方案。

已编辑

anubhava 给出的解决方案效果很好。感谢您的解决方案。

最佳答案

您可以使用:

RewriteEngine On

# maindomain -> https
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(?:www\.)?(website\.com)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [R,L]

# subdomain -> http
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^(?:www\.)?(sub\.website\.com)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R,L]

关于.htaccess - 主域为 https,子域为 http,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30287816/

相关文章:

internet-explorer - 为什么 IE 会在兼容模式之外重复发送图像的 GET 请求?

jquery - HTTP 状态代码 - 称为映射的函数

regex - .php 在添加尾部斜杠后以重写的 url 结尾

php - 某些情况下插入mysql时出现403错误(工作10次中的8次)

apache - 干净的URL重定向循环

http - Camel 从 http 到文件到我的文件系统

apache - RewriteRule 删除版本号

php 到 htaccess 重写 - 如果没有 $_POST 数据则重定向

apache - 内部 mod_rewrite,无重定向

.htaccess -> 域参数 -> https ://example. com/page 正在工作,而 https ://example. com/没有