简体   繁体   English

仅当提供https时,才从http重定向到https

[英]Redirect from http to https ONLY IF https is available

I use an in-house content management system written using PHP and running on Apache and Linux. 我使用内部的内容管理系统,该系统使用PHP编写并在Apache和Linux上运行。 The CMS has an install routine that automatically creates a .htaccess file that forces the redirect of http to https for all new isntallations. CMS具有一个安装例程,该例程会自动创建一个.htaccess文件,该文件会强制将所有新版本的http重定向到https。 This is all good if https is installed on that domain, but my question is, how can I modify the test so that .htaccess only forwards to https if https is available for that domain? 如果在该域上安装了https,这一切都很好,但是我的问题是, 如何修改测试,以便.htaccess仅在该域可以使用https的情况下才转发到https?

The important part of the .htaccess file: .htaccess文件的重要部分:

# Redirect users from http: to https:
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,QSA]

好的,首先,不要使用mod_rewrite (购买https://httpd.apache.org/docs/2.4/rewrite/avoid.html )并在其位置使用Redirect

Redirect "/" "https://www.example.com/"

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

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