使用htaccess的添加WWW以https支持 [英] use htaccess to add www with https support

查看:252
本文介绍了使用htaccess的添加WWW以https支持的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有很多code例子使用的.htaccess添加WWW到URL,但它们通常只限于使用HTTP。没有任何人有一个如何得到它在两种情况下工作的例子吗?

There are a lot of code examples for using .htaccess to add www to a url but they are usually confined to using http. does anybody have an example of how to get it to work in both cases?

推荐答案

肯定的:

RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

第二个条件会检查的 HTTPS 的环境变量(无论是关闭 )设置为并获取附加的取值中,然后可以用%1 。如果不匹配,%1 只是一个空字符串。

The second condition checks if the HTTPS environment variable (either on or off) is set to on and captures the appended s that is then available with %1. If it doesn’t match, %1 is just an empty string.

这篇关于使用htaccess的添加WWW以https支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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