简体   繁体   English

无法使用.htaccess强制使用SSL / https

[英]Unable to Force SSL/https using .htaccess

i'm using open-school php on my host and i'm trying to force ssl on my website but when i add this code 我在主机上使用开放学校php,并且试图在我的网站上强制使用ssl,但是当我添加此代码时

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

but then i'm unable to access my website as the browser says too many loops or redirects 但随后我无法访问我的网站,因为浏览器显示太多循环或重定向

The page isn't redirecting properly 页面未正确重定向

Firefox has detected that the server is redirecting the request for this address in a way that will never complete. Firefox已检测到服务器正在以永远无法完成的方式重定向对该地址的请求。

here is the orignal htacess file please help 这是原始的htacess文件,请帮助

    Options +FollowSymLinks
IndexIgnore */*
RewriteEngine On


#Admin
Rewriterule ^admin$ index.php?r=Cms/admin/home
#Install
Rewriterule ^install$ install.php?r=Install/default

# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !\.(js|ico|gif|jpg|png|css)$

# otherwise forward it to index.php
RewriteRule . index.php

Rather than using the %{SERVER_PORT} line, try this: 而不是使用%{SERVER_PORT}行,请尝试以下操作:

RewriteCond %{HTTPS} !=on

This is a complete .htaccess file that I use to force any website to SSL: 这是一个完整的.htaccess文件,我用来强制任何网站使用SSL:

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R,L]

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

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