将网站重定向到https

时间:2017-10-02 12:14:51

标签: apache .htaccess ssl redirect https

我已经通过123-Reg获得了SSL证书,我已经批准了,现在123-Reg建议我必须更新我的.htaccess文件,并将所有http请求重新路由到https

问题在于每次更新.htaccess时,网站都会关闭。

环顾四周,似乎我应该在.htaccess文件的顶部发布以下内容:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

因此,我当前的.htaccess文件如下所示:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 month"
ExpiresByType image/jpeg "access 1 month"
ExpiresByType image/gif "access 1 month"
ExpiresByType image/png "access 1 month"
ExpiresByType text/css "access 1 day"
ExpiresByType text/html "access 1 day"
ExpiresByType application/pdf "access 1 month"
ExpiresByType text/x-javascript "access 30 minutes"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 1 month"
</IfModule>
## EXPIRES CACHING ##
#Alternate default index page
DirectoryIndex index.php

我已经尝试过上面的代码,只是自己重写代码,但无济于事。应该注意的是,我并不特别擅长使用.htaccess的错综复杂!

我收到的错误消息(在IE Edge中)是:

Hmmm... cannot reach this page
Try this
Make sure that you’ve got the right web address: https://www.pixel8games.com
Search for "https://www.pixel8games.com" on Bing
Refresh the page
Details 
There were too many redirections.
Error Code: INET_E_REDIRECT_FAILED

当重定向代码不在.htaccess中时,我也可以手动输入网址中的https地址。

如果有人可以提供帮助,我将非常感激。 丹。

1 个答案:

答案 0 :(得分:0)

清除浏览器缓存并输入以下代码:

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://yourdomain.com/$1 [L,R]
相关问题