跳转到主要内容
你行网

Main navigation

  • 首页
  • Drupal
  • 编程与开发
  • 数据库
  • 操作系统与应用
  • 服务器与运维
  • 社区
User account menu
  • 登录

面包屑

  1. 首页

Apache 使用 mod_rewrite 将 HTTP 重定向到 HTTPS

由 hrs, 12 三月, 2022

Apache 的mod_rewrite可以很容易地要求在您的站点上使用 SSL,并可以轻松地重定向在键入 URL 时忘记添加 https 的用户。使用 Apache 将 http 重定向到 https 将确保您的网站(或其中的一部分)只能由使用 SSL 的客户访问。这比使用 SSLRequireSSL 更好,因为用户经常忘记输入 https 并且会被自动重定向。

在设置从 http 到 https 的 Apache 重定向之前,您需要执行以下操作:

  • 确保您的 SSL 证书已成功安装,以便您可以访问 https://www.yoursite.com(有关更多信息,请参阅我们的Apache SSL 安装说明)
  • 确保在 Apache 中启用了 mod_rewrite

现在您只需要编辑您的 httpd.conf 文件或指定您的虚拟主机的文件并添加这些行以将 http 重定向到 https:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{SERVER_NAME}/$1 [R,L]

 

在许多情况下,您还可以将这些行添加到您要将 http 重定向到 https 的文件夹中名为 .htaccess 的文件中。

现在,当访问者键入 http://www.yoursite.com/mypage.htm 时,服务器会自动将 http 重定向到 https,以便他们转到 https://www.yoursite.com/mypage.htm

注意:您还可以通过在配置文件或 .htaccess 文件中使用它来将单个页面从 http 重定向到 Apache 中的 http:

RewriteEngine On
RewriteRule ^apache-redirect-http-to-https\.html$ https://www.yoursite.com/apache-redirect-http-to-https.html [R=301,L]

 

  • 登录或注册以发表评论

文章标签

  • apache

评论

文章标签

CSS
Excel
ubuntu
php
vim
五笔
Linux
VPN
command
HTML
drupal 8
drupal 7
centos
composer
Mysql
drush
模块(module)
Drupal
JavaSrcipt
apache
drupal 9
英语
nerdtree
SEO
network
果树种植
surround
drupal10
主题(theme)
ssh
phpmyadmin
yum
二进制
权限
声音
ssl
selinux
HTML5
WireGuard
password
Dreamweaver
DDEV
flameshot
翻译
颜色
uploadprogress
firewalld
kernel
邮件验证
视图(views)
快捷键
gzip
xdebug
错误
电脑基础
ckeditor
C语言
简介
源地址
mbstring
certbot
php扩展
git
csharp
httpd
apt
电子秤
压缩解压
breadcrumb
表单
短信验证
AI
firmware
摄影
diff
superfish
重定向
drupal 11
网站备份
docker
版本号
tagclouds
java
RSS
adsense
电脑技巧
端口
KVM
simple_adsense
算法
youtube
JavaScript
cookie
badblocks
网站运营
计算机基础
RFID
zip
dns
标签优化
VUE
gimp
form
mod_expires 模块
赚钱
ip
http验证
curl
重定向,301
netstat
字段
maven
input
nginx
哈希值
npm
wps
更多

相关文章

  • 如何优化1GB RAM VPS的Apache,PHP和MySQL性能
  • centos7 httpd 运行不稳定出现重启现象
  • 在Apache服务器上安装SSL证书
  • ubuntu 开启url 重写模块
  • Apache2 Ubuntu默认页面
RSS源

友情链接 网站地图 版权信息 联系我们 网址导航 社区

Copyright © 2019 - 2021 你行网 版权所有  粤ICP备19072650号