.htaccess无法将http重定向到https

编程入门 行业动态 更新时间:2024-10-22 02:49:53
本文介绍了.htaccess无法将http重定向到https的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

I have domain www.supergenscript 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\ RewriteRule ^(.*)$ www.supergenscript/$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 (.*) %{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

本文发布于:2023-10-31 15:52:24,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1546555.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:重定向   htaccess   http   https

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!