在HTTPS中强制打开内部链接

时间:2019-07-10 06:29:34

标签: javascript html .htaccess https

我有一个网站在内部调用脚本和CSS:

<link href="css/bootstrap.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" href="css/slick.css">
<link href="css/style.css" rel="stylesheet" type="text/css" />
<link href="css/responsive.css" rel="stylesheet" type="text/css" />
<script src="js/jquery-1.12.4.min.js" type="text/javascript"></script>
<script src="js/jquery-easing.min.js" type="text/javascript"></script>
<script src="js/bootstrap.min.js" type="text/javascript"></script>
<script src="js/imageLoader-global.js"></script>
<script src="js/slick.js"></script>
<script src="js/TweenMax.min.js"></script>
<script src="js/ScrollMagic.min.js"></script>
<script src="js/animation.gsap.min.js"></script>
<script src="js/animation.js" type="text/javascript"></script>
<script src="js/vivus.min.js" type="text/javascript"></script>
<script src="js/slick.js" type="text/javascript"></script>
<script src="js/script.js" type="text/javascript"></script>

该网站以HTTPS打开,但是当我打开该网站并检查HTML时,这些内部链接正在以HTTP打开,这导致内容混合并呈现出不良外观。

如何强制所有这些链接在HTTPS中打开?

这是我目前的HTACCESS文件:

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

</IfModule>

网站以HTTPS打开,但是上面的资源正在以HTTP加载。

1 个答案:

答案 0 :(得分:0)

RewriteEngine On之后添加此规则

RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]