如何将所有非https URL重定向到https而不是子域 [英] how to redirect all non https url to https but not subdomain

查看:101
本文介绍了如何将所有非https URL重定向到https而不是子域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含两个子域的域,如果有人键入www.example.com或 http://example.com ,他应该重定向到 https://example.com ,但是在子域的情况下,他不应重定向,例如:如果他输入 http://subdomain.example.com ,则不应访问 https://subdomain.example.com 。我在下面使用通用的htaccess代码,

I have a domain having two subdomain, I want that if someone type www.example.com or http://example.com , he should redirect to https://example.com but in case of subdomain he shouldn't redirect, eg: if he type http://subdomain.example.com, he shouldn't go to https://subdomain.example.com. I am using below general htaccess code,

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%1%{REQUEST_URI}

但是此代码是将所有流量重定向到https(包括subomain)。请帮助我编写htaccess代码,该代码不会将子域重定向到https://,而将其他所有流量重定向到https

But this code is redirecting all trafic to https including subomain. please help me to write htaccess code which will not redirect subdomain to https:// but other all trafic to https

推荐答案

您应该尝试下面的代码。

I feel you should try the code below.

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !=subdomain.example.com
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} 

如果上述规则无效,则尝试用此规则替换上述规则

if above rules not worked than try to replace the above rule with this one

RewriteRule (.*) https://%{HTTP_HOST}%1%{REQUEST_URI}

这篇关于如何将所有非https URL重定向到https而不是子域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆