如何写htaccess的子站点重定向到HTTPS [英] How to write htaccess for subdomain redirection to https

查看:126
本文介绍了如何写htaccess的子站点重定向到HTTPS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何编写重定向example.com htaccess的规则,以www.example.com和我们也有子域,例如subdomain.example.cpm数,所以我需要将其重定向到的 https://subdomain.example.com 。但是当我写htaccess的规则是要循环。请发送怎么写这个条件。

How to write htaccess rules for redirect example.com to www.example.com and also we have number of subdomains for example subdomain.example.cpm so i need to redirect it to https://subdomain.example.com. but when i write htaccess rules it is going to loop. please send how to write conditions for this.

推荐答案

将这个code在 DOCUMENT_ROOT /的.htaccess 文件:

Put this code in your DOCUMENT_ROOT/.htaccess file:

RewriteEngine On

# example.com to www.example.com
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]

# http to https for subdomains
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]

这篇关于如何写htaccess的子站点重定向到HTTPS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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