.htaccess - htaccess 将所有流量重定向到 https ://www

标签 .htaccess redirect

我正在尝试将三个案例重定向到 https://www 。他们是:

http://
http://www
https://

我能够得到前两个,但不能得到最后一个。这是我使用的:

RewriteCond %{HTTPS} 关闭
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.*)$ [NC]
RewriteRule (.*) https://www.%1%{REQUEST_URI} [L,R=301]

最佳答案

您可以使用此规则在同一规则中添加 www 并启用 https:

RewriteCond %{HTTP_HOST} !^www\. [NC,OR]
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://www.%1%{REQUEST_URI} [R=301,L,NE]

要从 %{HTTP_HOST} 捕获值,您需要一个不是 OR 条件的条件。

关于.htaccess - htaccess 将所有流量重定向到 https ://www,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34658449/

相关文章:

laravel 4.2 https 无法加载 Assets 文件

facebook - NWebsec's “A potentially dangerous redirect was detected”与Facebook登录

.htaccess - apache 配置的等效值是多少

linux - 在 shell 脚本中使用 sed 替代不起作用

javascript - 是否可以根据时间进行重定向?

JavaScript 从 Tumblr 重定向到 WordPress

redirect - Nginx 在位置下返回

http - 从 SSL 中排除子域

php - 如何在特定文件 example.org/index.html 上强制使用 SSL?

css - HTACCESS 行阻止加载 CSS