.htaccess 重定向

Chrome and Firefox have started showing insecure warnings on sites without SSL certificates. Without SSL, your website will show insecure to the visitors. Therefore, using an SSL-encrypted connection for safety, accessibility or PCI compliance reasons is necessary. It becomes very important to redirect from HTTP to HTTPS.

Chrome和Firefox已开始在没有SSL证书的网站上显示不安全的警告。 没有SSL,您的网站将对访问者显示不安全。 因此,出于安全性,可访问性或PCI合规性的原因,必须使用SSL加密的连接。 从HTTP重定向到HTTPS变得非常重要。

什么是SSL? (What is SSL?)

SSL (Secure Sockets Layer) is a standard security protocol for establishing encrypted links between a web server and a browser in an online communication.

SSL(安全套接字层)是一种标准安全协议,用于在在线通信中的Web服务器和浏览器之间建立加密链接。

The usage of SSL technology ensures that all data transmitted between the web server and browser remains encrypted.

SSL技术的使用可确保在Web服务器和浏览器之间传输的所有数据均保持加密状态。

An SSL certificate is necessary to create SSL connection. You would need to give all details about the identity of your website and your company as and when you choose to activate SSL on your web server. Following this, two cryptographic keys are created — a Private Key and a Public Key.

SSL证书是创建SSL连接所必需的。 当您选择在Web服务器上激活SSL时,您需要提供有关网站和公司身份的所有详细信息。 此后,将创建两个加密密钥-私钥和公钥。

Learn More: Why SSL is Critical?

了解更多:为什么SSL至关重要?

In order to force your web traffic to use HTTPS, edit the codes in the .htaccess file.

为了强制您的网络流量使用HTTPS,请编辑.htaccess文件中的代码

Before we move onto redirecting HTTP to HTTPS, here’s how you can edit .htaccess file. If you already know skip to Redirection steps.

在开始将HTTP重定向到HTTPS之前,这里是如何编辑.htaccess文件的方法。 如果您已经知道跳到重定向步骤。

编辑.htaccess文件 (Editing .htaccess File)

There are instructions/directives in the .htaccess file that tell the server how to act in certain scenarios and directly affects how your website functions. Common directives in .htaccess file:

.htaccess文件中有指令/指令,它们告诉服务器在某些情况下如何操作并直接影响网站的功能。 .htaccess文件中的常见指令:

  • Redirects重新导向
  • Rewriting URLs重写URL

Ways to edit an .htaccess file:

编辑.htaccess文件的方法:

  1. Edit the file on your computer and upload it to the server using FTP.在计算机上编辑文件,然后使用FTP将其上传到服务器。
  2. Use “Edit” mode in FTP program that allows you to edit a file remotely.在FTP程序中使用“编辑”模式,该模式允许您远程编辑文件。
  3. Use a text editor and SSH to edit the file.使用文本编辑器和SSH编辑文件。
  4. Use the File Manager in cPanel to edit the file.

    使用cPanel中的文件管理器来编辑文件。

在cPanel文件管理器中编辑.htaccess (Editing .htaccess in cPanel File Manager)

Note: Backup your website in case something goes wrong.

注意:备份您的网站,以防出现问题。

  1. Login to cPanel登录到cPanel
  2. Files > File Manager > Document Root for:文件>文件管理器>文档根目录:
  3. Now select the domain name you want to access现在选择您要访问的域名
  4. Check “Show Hidden Files (dotfiles)”选中“显示隐藏的文件(点文件)”
  5. Click “Go”点击“开始”
  6. After a new tab or window opens, look for the .htaccess file.打开新的选项卡或窗口后,查找.htaccess文件。
  7. Right click on the .htaccess file and click on “Code Edit” on the menu.右键单击.htaccess文件,然后在菜单上单击“代码编辑”。
  8. A dialogue box may pop up asking about encoding. Click “Edit” button to continue.可能会弹出一个对话框,询问有关编码的信息。 单击“编辑”按钮继续。
  9. Edit the file编辑档案
  10. “Save Changes” when done.完成后“保存更改”。
  11. Test your website to make sure it is done correctly. In case, there is an error, restore to the previous version and try again.测试您的网站,以确保其正确完成。 如果出现错误,请还原到以前的版本,然后重试。
  12. Once you are done, click “Close” to close the window.完成后,单击“关闭”以关闭窗口。

将HTTP重定向到HTTPS (Redirecting HTTP to HTTPS)

1.重定向所有网络流量 (1. Redirect All Web Traffic)

If you have existing code in your .htaccess, add the following:

如果您的.htaccess中已有代码,请添加以下内容:

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

2.仅重定向特定域 (2. Redirect Only a Specific Domain)

For redirecting a specific domain to use HTTPS, add the following:

要重定向特定域以使用HTTPS,请添加以下内容:

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

3.仅重定向特定的文件夹 (3. Redirect Only a Specific Folder)

Redirecting to HTTPS on a specific folder, add the following:

重定向到特定文件夹上的HTTPS,添加以下内容:

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

Note: Replace “yourdomain” with your actual domain name wherever required. Also, in case of the folder, replace /folder with the actual folder name.

注意:如有需要,请用您的实际域名替换“yourdomain”您的域名“yourdomain” 。 另外,对于文件夹,请用实际的文件夹名称替换/folder

Think it was helpful? Share this article to help others come on HTTPS.

觉得有帮助吗? 分享本文以帮助其他人使用HTTPS。

翻译自: https://www.freecodecamp.org/news/how-to-redirect-http-to-https-using-htaccess/

.htaccess 重定向

.htaccess 重定向_如何使用.htaccess将HTTP重定向到HTTPS相关推荐

  1. linux tee 重定向_快乐的linux命令行-重定向

    整理自<快乐的linux命令行一书>. linux系统版本: Ubuntu 17.04 本章,我们将介绍命令行最酷的特性,叫做I/O重定向,通过这个工具,可以重定向命令的输入输出,命令的输 ...

  2. usb禁止重定向_远程桌面中的USB重定向技术解析(功能篇)

    在运行远程和虚拟桌面的数据中心内,网络管理员可以对计算环境的各个方面进行控制.只有一点除外,就是本地外围设备. 本地外围设备包括所有连接到终端上的设备,例如USB驱动器.鼠标或打印机.它们逐渐成为终端 ...

  3. java httpclient 重定向_用Apache HttpClient实现URL重定向

    很多网站都使用了URL重定向技术,把一个原始请求从一个位置路由到另一个位置.原因可能是多方面的,比如域名转发.URL缩写.隐私保护.在同一网站维持相似的域名等. 本文讲述怎样使用Apache HTTP ...

  4. java httpclient 重定向_如何在HttpClient中自动重定向(java,apache)

    我创建了httpClient并设置了设置 HttpClient client = new HttpClient(); client.getParams().setCookiePolicy(Cookie ...

  5. java 怎么做302重定向_利用Java怎么获取302重定向后的URL

    利用Java怎么获取302重定向后的URL 发布时间:2021-01-22 16:59:02 来源:亿速云 阅读:57 作者:Leah 本篇文章为大家展示了利用Java怎么获取302重定向后的URL, ...

  6. nginx配置url重定向_详解nginx配置url重定向-反向代理

    https://www.jb51.net/article/99996.htm 本文系统:Centos6.5_x64 三台主机:nginx主机,hostname: master.lansgg.com  ...

  7. 重定向index.php,使用htaccess将all重定向到index.php

    我正在编写一个简单的基于PHP的MVC-ish框架.我希望这个框架能够安装在任何目录中. 我的PHP脚本抓取请求uri并将其分解为段.它使段1成为控制器,段2成为行动.当我这样做时,这一切都很好: 它 ...

  8. php的.htaccess文件目录,子目录中的.htaccess文件

    子目录中的.htaccess文件 在计算机的文件系统中,每个文件和目录各自都配有许可权限,这些权限规定了哪些文件是可读的,哪些是可写入的,哪些是可执行的. 许可权限系统是一种保护用户网站安全性的基本措 ...

  9. 如何阻止ajax自动重定向_重发和重定向有什么区别与重定向应用

    重发和重定向有什么区别 重发 方式1: request.getRequestDispatcher("new.jsp").forward(request, response);//转 ...

最新文章

  1. keras 的 example 文件 imdb_fasttext.py 解析
  2. mpython掌控板作品_mPython掌控板Easy-IoT物联
  3. poj1185炮兵阵地
  4. 2给我背书_让优秀的人做你的背书人
  5. VTK:图像方向用法实战
  6. php的webservice的soapheader认证问题
  7. 关于爬虫中遇到的问题
  8. 软件开发了10年,迷茫了
  9. 香肠派对电脑版_香肠派对先行服s7赛季下载-香肠派对先行服s7赛季最新版下载...
  10. 前端学习(2137):webpack的介绍和安装
  11. POJ 1028 浏览器前进后退(双栈)
  12. C++二分查找,时间复杂度是O(logn)
  13. 20145201 《Java程序设计》第六周学习总结
  14. 【转载】python中strip(),lstrip(),rstrip()函数的区别
  15. 磁盘碎片与闪存摩擦均衡介绍
  16. 项目使用mybatis-plus采用mysql/clickhouse多数据库配置,报错Invalid bound statement (not found)
  17. Java实战项目-移动电商秒杀系统seckill优化
  18. A*寻路算法之解决目标点不可达问题
  19. 峰哥买房用的贝壳app,他们的大数据平台如何实现的?
  20. 医院信息科招聘计算机专业试题,医院信息科招收计算机科学与技术专业的笔试试题...

热门文章

  1. 【今日CS 视觉论文速览】Tue, 15 Jan 2019
  2. 内部类 java 1614957119
  3. linux-简单进程查询
  4. sublime-安装插件
  5. BZOJ 1032 JSOI 2007 祖码Zuma 区间DP
  6. BZOJ 3038: 上帝造题的七分钟2【线段树区间开方问题】
  7. lintcode 中等题:Single number III 落单的数III
  8. java 自动装箱自动拆箱
  9. 服务器磁盘扩展容量操作流程
  10. Revit二次开发之“为Ribbon设置快捷键”