[英].htaccess not redirecting http to https
I have domain www.supergenscript.com hosted on a cloud server where only an under construction index page is uploaded. 我将域www.supergenscript.com托管在仅上载正在建设的索引页面的云服务器上。 There was no .htaccess file present so I created a .htaccess file and uploaded it in the server using filezilla.
目前没有.htaccess文件,因此我创建了.htaccess文件,并使用filezilla将其上传到服务器中。 I want to redirect my website from http to https automatically.
我想将我的网站从http自动重定向到https。 These are the contents of my .htaccess file.
这些是我的.htaccess文件的内容。
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{HTTP_HOST} ^(www\.)?supergenscript\.com
RewriteRule ^(.*)$ https://www.supergenscript.com/$1 [R=301, L]
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.
我希望这能正常工作,但这不会自动将我的域重定向到https。 Please help me with this.
请帮我解决一下这个。
You can use: 您可以使用:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</IfModule>
Upload the .htaccess to your root directory. 将.htaccess上载到您的根目录。
Line 1: Checks the module - mod_rewrite is activated. 第1行:检查模块-mod_rewrite已激活。
Line 2: Enables the Rewrite Engine. 第2行:启用重写引擎。
Line 3: Checks if HTTPS-Protocol is switched on, if not then execute the contents of line 4. 第3行:检查HTTPS协议是否已打开,如果未打开,则执行第4行的内容。
Line 4: Redirects all requests to HTTPS via status code 301 = (permanent redirect). 第4行:通过状态代码301 =(永久重定向)将所有请求重定向到HTTPS。
Line 5: Close - mod_rewrite! 第5行:关闭-mod_rewrite!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.