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

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

问题描述

有很多使用 .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 环境变量(onoff)是否设置为 on并捕获附加的 s,然后可用于 %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 添加带有 https 支持的 www的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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