需要将所有流量重定向到 https [英] Need to redirect all traffic to https

查看:32
本文介绍了需要将所有流量重定向到 https的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将任何流向 http://example.com 的流量重定向到 https://example.com

I want to redirect any traffic that goes to http://example.com to https://example.com

对于 http://example.com/abouthttps://example.com/about

我以为会是这样:

RewriteCond %{HTTP_HOST} ^example.com$ [NC]
RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]

推荐答案

这对我有用:

RewriteEngine on
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

如果流量通过非 SSL HTTP 传入,则重定向到用户最初尝试访问的任何页面的 HTTP 等效项.它也不涉及任何 mod_rewrite 选项,因此很容易阅读.

If the traffic is coming in over non-SSL HTTP, then redirect to the HTTP equivalent of whatever page the user was originally trying to access. It also doesn't involve any mod_rewrite options, so it's easy to read.

旁白:为什么每个人都觉得需要明确设置重定向的 HTTP 代码并将他们的重写之一标记为最后"一个?说真的,就在最近几天,我看到了几十条看起来一模一样的 htaccess 规则.

Side rant: why does everyone feel the need to explicitly set the HTTP code of the redirect and mark one of their rewrites as the "last" one? Seriously, I've seen dozens of same-looking htaccess rules in just the last few days.

这篇关于需要将所有流量重定向到 https的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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