Apache-如何仅将HTTP请求转换为https? [英] Apache - how to make http requests into https only?

查看:176
本文介绍了Apache-如何仅将HTTP请求转换为https?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何判断 http://ttt.com 还是 http://www.ttt.com ,将其重定向到 https://www.ttt.com

How to tell if http://ttt.com or http://www.ttt.com is used by the user, redirect it to https://www.ttt.com ?

httpd.conf:

httpd.conf:

<VirtualHost *:80>
 ServerName www.ttt.com
 ServerAlias ttt.com
 DocumentRoot /home/www/html/ttt/public
 <Directory /home/www/html/ttt/public>
    #Options ExecCGI
    #AddDefaultCharset utf-8
    DirectoryIndex index.php
    AllowOverride All
    Order allow,deny
    Allow from all
 </Directory>
</VirtualHost>

.htaccess:

.htaccess :

RewriteEngine On
############################################
## always send 404 on missing files in these folders
#RewriteCond %{REQUEST_URI} !^/(files)/
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]


推荐答案

尝试主目录.htaccess文件中的以下代码:

Try the following Code at the main directory .htaccess file :

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\. [NC,OR]
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R]

这篇关于Apache-如何仅将HTTP请求转换为https?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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