1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > .htaccess 重定向_如何使用.htaccess将HTTP重定向到HTTPS

.htaccess 重定向_如何使用.htaccess将HTTP重定向到HTTPS

时间:2019-09-08 16:08:56

相关推荐

.htaccess 重定向_如何使用.htaccess将HTTP重定向到HTTPS

.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服务器和浏览器之间传输的所有数据均保持加密状态。

AnSSL certificateis 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文件的方法:

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

Use the File Manager incPanelto edit the file.

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

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

Note:Backup your website in case something goes wrong.

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

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

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

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

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

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

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

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

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

RewriteEngine OnRewriteCond %{SERVER_PORT} 80RewriteCond %{REQUEST_URI} folderRewriteRule ^(.*)$ /folder/$1 [R,L]

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

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

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

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

翻译自: /news/how-to-redirect-http-to-https-using-htaccess/

.htaccess 重定向

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。