.htaccess无法将http重定向到https [英] .htaccess not redirecting http to https

查看:112
本文介绍了.htaccess无法将http重定向到https的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将域 www.supergenscript.com 托管在仅在建索引页位于其中的云服务器上已上传.目前没有.htaccess文件,因此我创建了.htaccess文件,并使用filezilla将其上传到服务器中.我想将我的网站从http自动重定向到https.这些是我的.htaccess文件的内容.

I have domain www.supergenscript.com hosted on a cloud server where only an under construction index page is uploaded. There was no .htaccess file present so I created a .htaccess file and uploaded it in the server using filezilla. I want to redirect my website from http to https automatically. These are the contents of my .htaccess file.

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

除这些代码行外,没有其他内容.我希望这能正常工作,但这不会自动将我的域重定向到https.请帮助我.

Nothing else except these lines of codes is written there. I expected this to work but this is not redirecting my domain to https automatically. Please help me with this.

推荐答案

您可以使用:

<IfModule mod_rewrite.c>
 RewriteEngine On
 RewriteCond %{HTTPS} off
 RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</IfModule>

将.htaccess上载到您的根目录.

Upload the .htaccess to your root directory.

第1行:检查模块-mod_rewrite已激活.

Line 1: Checks the module - mod_rewrite is activated.

第2行:启用重写引擎.

第3行:检查HTTPS协议是否已打开,如果未打开,则执行第4行的内容.

Line 3: Checks if HTTPS-Protocol is switched on, if not then execute the contents of line 4.

第4行:通过状态代码301 =(永久重定向)将所有请求重定向到HTTPS.

Line 4: Redirects all requests to HTTPS via status code 301 = (permanent redirect).

第5行:关闭-mod_rewrite!

Line 5: Close - mod_rewrite!

这篇关于.htaccess无法将http重定向到https的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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