简体   繁体   English

强制所有用户使用.htaccess使用SSL

[英]Forcing all users to go through SSL with .htaccess

I just installed a SSL certificate on my site, but now I'm facing a problem when I try to force all users to go through secure SSL (HTTPS) instead of HTTP. 我刚刚在自己的站点上安装了SSL证书,但是现在当我试图强制所有用户通过安全SSL(HTTPS)而不是HTTP时遇到了问题。 I found that the way to to it is using the code below on .htaccess 我发现使用它的方法是在.htaccess中使用以下代码

#Force SSL on entire site
RewriteEngine On
RewriteBase /
RewriteCond %{ENV:HTTPS} !on [NC]
RewriteRule ^(.*)$ https://example.com/$1 [R,L]

So far, it's not working, I get a redirect loop error. 到目前为止,它不起作用,我收到了重定向循环错误。

在此处输入图片说明

It's redirecting to the SSL URL, but not working.. without the .htaccess rule it works when i type manually https://example.com 它重定向到SSL URL,但是不起作用..没有.htaccess规则,当我手动键入https://example.com时它可以工作

I have no idea if this will work for you but I do the same thing for my site and this is the code in my .htaccess file. 我不知道这是否对您有用,但是我对我的网站也做同样的事情,这是我的.htaccess文件中的代码。 I am sure I got it from somewhere here on Stack Overflow. 我确定我是从Stack Overflow上的某个地方得到的。

<IFModule mod_rewrite.c>
  RewriteEngine on
  RewriteCond %{HTTPS} off
  RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
</IFModule>

Try this: 尝试这个:

RewriteEngine On 
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]

Should work fine... 应该工作正常...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM