时间:2019-11-12加入收藏
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP:From-Https} !^on$ [NC]
#RewriteCond %{HTTPS} !^on$ [NC] # 非亚数机房用这一行替换上一行规则
RewriteCond %{HTTP_HOST} ^(www.)?abc.com$ [NC] # 将abc.com和www.abc.com跳转到https://www.abc.com,防止apache子站继承上级目录.htaccess受影响
RewriteRule ^(.*)$ https://www.xiuzhanwang.com/$1 [R=301,L]
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP:From-Https} !^on$ [NC]
RewriteCond %{HTTP_HOST} ^(www.)?abc.com$ [NC] # 将abc.com和www.abc.com跳转到https://www.abc.com,防止apache子站继承上级目录.htaccess受影响
RewriteRule ^(.*)$ https://www.xiuzhanwang.com/$1 [R=301,L]
</IfModule>
server
{
listen 80;
server_name abc.com;
rewrite ^(.*) https://www.abc.com$1 permanent; # abc.com对应修改为您自已的域名
}
亚数机房CDN部署的SSL添加下面代码
if ( $http_from_https != 'on' ){
rewrite ^(.*) https://www.xiuzhanwang.com$1 permanent; # abc.com对应修改为您自已的域名
}
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="301" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTP_FROM_HTTPS}" pattern="^on$" negate="true" />
<!-- <add input="{HTTPS}" pattern="^on$" negate="true" /> --> # 非亚数机房用这一行替换上一行规则
</conditions>
<action type="Redirect" url="https://www.xiuzhanwang.com/{R:1}" redirectType="Permanent" /> # www.abc.com对应修改为您自已的域名
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="301" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTP_FROM_HTTPS}" pattern="^on$" negate="true" />
</conditions>
<action type="Redirect" url="https://www.xiuzhanwang.com/{R:1}" redirectType="Permanent" /> # www.abc.com对应修改为您自已的域名
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
<script type="text/javascript">
var url = window.location.href;
if (url.indexOf("https") < 0) {
url = url.replace("http:", "https:");
window.location.replace(url);
}
</script>
<script language="JavaScript" type="text/JavaScript">
function redirect()
{
var loc = location.href.split(':');
if(loc[0]=='https')
{
location.href='http:'+loc[1];
}
}
οnlοad=redirect
</script>
http跳转https的方法较多,以上仅供参考。if ($_SERVER["HTTPS"] <> "on")
{
$xredir="https://".$_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
header("Location: ".$xredir);
}
TGA: