0

我想知道是否有人可以提供帮助。我们希望能够将我们的网站重定向到全球的 https 版本。已安装 SSL 证书,并且该站点的 https 版本处于活动状态并且可以正常工作。我尝试了以下方法。

www 根目录中的 web.config。

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
    <rewrite>
        <rules>
            <rule name="SSL" stopProcessing="true">
                <match url="^(.*)$"  />
                    <conditions>
                        <add input="{HTTP_X_FORWARDED_PROTO}" pattern="https" negate="true"/>
                    </conditions>
                <action type="Redirect" redirectType="Found" url="https://{HTTP_HOST}/{R:1}" />
            </rule>
        </rules>
    </rewrite>
</system.webServer>

www 根目录中的 .htaccess,并在托管服务提供商上启用了 URL 重写。

RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^(.*)$ https://mysitedomain.com/$1 [R=301,L]

我在更改和删除浏览器缓存之后回收了应用程序池。两种方法都不起作用。无论如何尝试验证任何一种方法以确保正在读取文件,因为它似乎没有做任何事情。是否可以尝试使用全球 asa ?如果您需要任何进一步的信息,请询问。

编辑以提供有关托管环境的更多信息。我们正在使用一个运行 Windows 2003 的共享云托管平台(这很容易在不同平台之间切换),并且通过 Web 门户访问。该站点运行自己的应用程序池,我们可以对其进行回收。有激活和停用 URL 重写的选项。这里的描述。

启用“重写”模块将允许您在 Windows 或混合模式网站上的 .htaccess 文件中使用 Apache mod_rewrite 样式功能。例如,可以将 /store/products/televisions 等 URL 重写为 /store.php?type=products&category=televisions 以优化搜索引擎。有关详细信息,请参阅以下外部 URL。

我能够在逐页的基础上硬编码 SSL 重定向,但在全球范围内,无论我尝试什么,无论是 web.config 还是 .htaccess 似乎都没有被拾取。

4

2 回答 2

0

可能有不同的方法可以做到这一点。只需像这样在脚本中重定向

<%
   If Request.ServerVariables("SERVER_PORT")=80 Then
      Dim strSecureURL
      strSecureURL = "https://"
      strSecureURL = strSecureURL & Request.ServerVariables("SERVER_NAME")
      strSecureURL = strSecureURL & Request.ServerVariables("URL")
      strSecureURL = strSecureURL & "?" & Request.ServerVariables("QUERY_STRING")
      Response.Redirect strSecureURL
   End If
%>

请参阅如何:使用 ASP 对特定页面强制使用 SSL

于 2018-10-19T09:27:18.010 回答
0

要将网站从 重定向HTTPHTTPS,请尝试以下操作。

如果你正在使用Linux & cPanel – Force HTTPS using .htaccess

RewriteCond %{HTTPS} !on [OR]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule (.*) https://www.domainname.com%{REQUEST_URI} [L,R=301]

如果你正在使用Windows & Plesk – Force HTTPS using web.config

<configuration>
<system.webServer>
<rewrite>
    <rules>
       <rule name="HTTP to HTTPS redirect" stopProcessing="true"> 
         <match url="(.*)" /> 
         <conditions> 
           <add input="{HTTPS}" pattern="off" ignoreCase="true" />
         </conditions> 
         <action type="Redirect" redirectType="Permanent" url="https://{HTTP_HOST}/{R:1}" />
       </rule> 
    </rules>
</rewrite>
</system.webServer>
</configuration>

不要忘记清除缓存

于 2018-10-17T14:42:46.993 回答