prePEND'WWW'使用的.htaccess和放大器的HTTPS URL; mod_rewrite的 [英] Prepend 'www' to an HTTPS url using .htaccess & mod_rewrite

查看:125
本文介绍了prePEND'WWW'使用的.htaccess和放大器的HTTPS URL; mod_rewrite的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样一个两难境地。用下面的code,我能够迫使SSL任何非SSL URL,但是当用户(和谷歌的结果)把用户的 http://mysite.co.za 然后我们打的问题,因为URL,然后改写为 https://mysite.co.za

由于这样的事实,我的证书绑定到www.mysite.co.za立即抛出,因为在URL中缺少WWW的安全错误。

有人能指出一个方法来对WWW添加到域时域开始​​使用HTTPS而不是HTTP?

许多AP preciated。

和目前的code添加https://开头如下:

 的RewriteCond%{HTTP_HOST}!^ WWW \。
的RewriteCond%{HTTPS}等^关于(S)|
重写规则^的http%1:​​//www.% {HTTP_HOST}%{REQUEST_URI} [L,R = 301]
 

解决方案
  

有人能指出一个方法来对WWW添加到域时域开始​​使用HTTPS而不是HTTP?

所以,你想这样的:

  • 如果主机不启动与WWW:
    • 如果连接是安全的,什么也不做。在这种情况下,你已经有点犯糊涂了,因为用户已经看到主机不匹配警告。
    • 如果该连接是不安全的重定向到的https://www.% {HTTP_HOST}%{REQUEST_URI}

您当前的规则:

 的RewriteCond%{HTTP_HOST}!^ WWW \。
的RewriteCond%{HTTPS}等^关于(S)|
重写规则^的http%1:​​//www.% {HTTP_HOST}%{REQUEST_URI} [L,R = 301]
 

此规则失败的你,因为它增加了万维网,无论是否连接牢固与否。此外,它让普通的HTTP是(无着的https://)的方式。

这是满足上面您的要求的规则是

 #如果主机不启动以www。
的RewriteCond%{HTTP_HOST}!^ WWW \。
#,然后连接并不安全
的RewriteCond%{HTTPS} =
#前锋
重写规则^ HTTPS://www.% {HTTP_HOST}%{REQUEST_URI} [R = 301]
 

标记是不必要的,因为重定向结束重写。

I have a dilemma with this one. With the following code I am able to force SSL on any non SSL url, however when the user (and results from Google) take the user to http://mysite.co.za then we hit an issue as the url is then rewritten to https://mysite.co.za

Due to the fact that my certificate is bound to www.mysite.co.za it immediately throws a security error because of the missing 'www' in the url.

Can someone point out a way to add the www to the domain when the domain starts with HTTPS and not HTTP?

Much appreciated.

And the current code to add the https:// is as follows:

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

解决方案

Can someone point out a way to add the www to the domain when the domain starts with HTTPS and not HTTP?

So you want this:

  • If the host does not start with www:
    • If the connection is secure, do nothing. In this case you're already screwed anyway, because the user has already seen the host mismatch warning.
    • If the connect is not secure redirect to https://www.%{HTTP_HOST}%{REQUEST_URI}

Your current rule:

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

This rule fails on you because it adds www no matter whether the connection is secure or not. Additionally, it keeps plain http the way it is (no forward to https://).

The rule that satisfy your requirements above is

#if the host does not start with www.
RewriteCond %{HTTP_HOST} !^www\.
#and the connection is not secure
RewriteCond %{HTTPS} =""
#forward
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301]

The L flag is unnecessary because a redirect ends the rewriting.

这篇关于prePEND'WWW'使用的.htaccess和放大器的HTTPS URL; mod_rewrite的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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