htaccess的重定向到HTTPS secure.domain.com,非HTTPS来www.domain.com [英] htaccess redirect HTTPS to secure.domain.com, non https to www.domain.com
本文介绍了htaccess的重定向到HTTPS secure.domain.com,非HTTPS来www.domain.com的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
不知道如何以最佳方式编写以下规则:
- 所有安全(HTTPS)的流量应该重定向到 https://secure.domain.com
- 要secure.domain.com非安全请求应该重定向到 https://secure.domain.com
- 所有其他非安全请求应该去 http://www.domain.com
- 最后,所有非www请求应该重定向到www,除了安全子域。
解决方案
尝试添加以下到您的域的根文件夹htaccess文件。
RewriteEngine叙述上
的RewriteBase /
#到secure.domain.com非安全请求应该重定向到https://secure.domain.com
的RewriteCond%{} HTTPS关闭
的RewriteCond%{HTTP_HOST} ^安全\\。域\\ .COM $ [NC]
。重写规则* https://开头%{HTTP_HOST}%{REQUEST_URI} [L,R = 301]#ALL安全(HTTPS)的流量应该重定向到https://secure.domain.com
的RewriteCond%{} HTTPS上
的RewriteCond%{HTTP_HOST}!^安全\\。域\\ .COM $ [NC]
。重写规则* HTTPS://secure.domain.com% {REQUEST_URI} [L,R = 301]
#ALL其他非安全请求应该去http://www.domain.com
#Lastly,所有非www请求应该重定向到www,除了安全子域。
的RewriteCond%{} HTTPS关闭
的RewriteCond%{HTTP_HOST}!^万维网\\。域\\ .COM $ [NC]
。重写规则*的http://www.domain.com% {REQUEST_URI} [L,R = 301]
Not sure how to best write the following rules:
- All secure (HTTPS) traffic should redirect to https://secure.domain.com
- Non-secure requests to secure.domain.com should redirect to https://secure.domain.com
- All other non-secure requests should go to http://www.domain.com
- Lastly, all non-www requests should redirect to www, except the "secure" subdomain.
解决方案
Try adding the following to your htaccess file in the root folder of your domain.
RewriteEngine on
RewriteBase /
#Non-secure requests to secure.domain.com should redirect to https://secure.domain.com
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^secure\.domain\.com$ [NC]
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
#All secure (HTTPS) traffic should redirect to https://secure.domain.com
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} !^secure\.domain\.com$ [NC]
RewriteRule .* https://secure.domain.com%{REQUEST_URI} [L,R=301]
#All other non-secure requests should go to http://www.domain.com
#Lastly, all non-www requests should redirect to www, except the "secure" subdomain.
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !^www\.domain\.com$ [NC]
RewriteRule .* http://www.domain.com%{REQUEST_URI} [L,R=301]
这篇关于htaccess的重定向到HTTPS secure.domain.com,非HTTPS来www.domain.com的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文