2016-11-05 13 views
0

301ステータスコードを返しながら、すべてのHTTPトラフィックをhttps に強制的にリダイレクトしようとしています。 私はこれを私のWeb.Release.configファイルに入れました。web.config 301ステータスコードのhttpsにリダイレクト

<rewrite> 
    <rules> 
    <rule name="Redirect to https" xdt:Transform="Insert"> 
     <match url="(.*)"/> 
     <conditions> 
     <add input="{HTTPS}" pattern="Off"/> 
     <add input="{REQUEST_METHOD}" pattern="^get$|^head$" /> 
     </conditions> 
     <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" statusCode="301" redirectType="Permanent" /> 
    </rule> 
    </rules> 
</rewrite> 

と私は307代わりの301を得続けます。 301ステータスコードを返すように強制するにはどうすればよいですか?

答えて

1

<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" statusCode="301" redirectType="Permanent" />

あなたのコードによると、我々はそれが301ステータスコードを返す必要があり、あなたがredirectType="Permanent"を指定することを見つけることができます。私は私の側で問題を再現しようとしました、ここに私の設定ファイルです。

のWeb.config

<?xml version="1.0" encoding="utf-8"?> 
<!-- 
    For more information on how to configure your ASP.NET application, please visit http://go.microsoft.com/fwlink/?LinkId=169433--> 
<configuration> 
<system.web> 
    <compilation debug="true" targetFramework="4.5"/>  <httpRuntime targetFramework="4.5"/> 
    </system.web> 
    <system.codedom> 
    <compilers> 

     <compiler language="c#;cs;csharp" extension=".cs" 
    type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" 
    warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701"/> 
     <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" 
    type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" 
    warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+"/> 
    </compilers> 
    </system.codedom> 
</configuration> 

Web.Release.config

<?xml version="1.0" encoding="utf-8"?> 

<!-- For more information on using web.config transformation visit http://go.microsoft.com/fwlink/?LinkId=125889 --> 

<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform"> 
    <!--In the example below, the "SetAttributes" transform will change the value of "connectionString" to use "ReleaseSQLServer" only when the "Match" locator finds an attribute "name" that has a value of "MyDB". 

    <connectionStrings> 
     <add name="MyDB" connectionString="Data Source=ReleaseSQLServer;Initial Catalog=MyReleaseDB;Integrated Security=True" 
    xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/> 
    </connectionStrings>--> 
    <system.web> 
    <compilation xdt:Transform="RemoveAttributes(debug)" /> 
    <!--In the example below, the "Replace" transform will replace the entire 
     <customErrors> section of your web.config file. 
     Note that because there is only one customErrors section under the 
     <system.web> node, there is no need to use the "xdt:Locator" attribute. 

     <customErrors defaultRedirect="GenericError.htm" mode="RemoteOnly" xdt:Transform="Replace"> 
     <error statusCode="500" redirect="InternalError.htm"/> 
     </customErrors>--> 
    </system.web> 
    <system.webServer xdt:Transform="Insert"> 
    <rewrite> 
     <rules> 
     <rule name="Redirect to https"> 
      <match url="(.*)"/> 
      <conditions> 
      <add input="{HTTPS}" pattern="Off"/> 
      <add input="{REQUEST_METHOD}" pattern="^get$|^head$" /> 
      </conditions> 
      <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" /> 
     </rule> 
     </rules> 
    </rewrite> 
    </system.webServer> 
</configuration> 

私は私のウェブサイトを訪問するとき、私は、ネットワークツールで301ステータスコードを見ることができました。私が代わりに301の307を得続ける

enter image description here

にはどうすれば301ステータスコードを返すように強制することができますか?

Web.configファイルを確認し、ステータスコードを変更する他のURL書き換えルールを定義することができます。

+0

これを書いたものをどこから探し始めるべきなのか?私は他のリダイレクションルールを持っていません –

+0

奇妙なことに、クロムが307を返すだけです。FFとエッジは301リダイレクトを示します。 –

関連する問題