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

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

问题描述

我想重定向去 http://example.com 到的 https://example.com

相同 http://example.com/about 到的 https://example.com/about

我认为这将是这样的:

 的RewriteCond%{HTTP_HOST} ^例如\ .COM $ [NC]
重写规则^(。*)$ https://example.com/$1 [R = 301,L]
 

解决方案

这对我的作品:

  RewriteEngine叙述上
的RewriteCond%{} HTTPS关闭
重写规则HTTPS(*)://%{HTTP_HOST}%{REQUEST_URI}
 

如果流量即将超过非SSL的HTTP,然后重定向到HTTP等价的任何网页,用户最初尝试访问。它也没有涉及任何mod_rewrite的选项,所以它很容易阅读。

边咆哮:为什么每个人都觉得有必要明确设置重定向的HTTP code和纪念他们的重写的一个最后一个?说真的,我已经看到了在刚刚过去的几天里几十个相同的外观htaccess的规则。

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

same for http://example.com/about to https://example.com/about

I thought it would be something like this:

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

解决方案

This works for me:

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

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.

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天全站免登陆