簡體   English   中英

web.config 301重定向,Windows托管

[英]web.config 301 redirects, windows hosting

我正在努力使web.config文件可用於重定向-我是第一次這樣做。 我一直在嘗試在本網站和其他地方找到的許多不同代碼。 我們有HTTPS網站,我需要將HTTP url-s重定向到HTTPS。 該網站使用HTML編寫,並且我們擁有Windows托管服務。

我設置了一個web.config文件,並在下面添加了代碼。

<?xml version="1.0" encoding="utf-8"?>
<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="Found" url="https://{HTTP_HOST}/{R:1}" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

我在這里想念什么嗎? 還是需要一些時間才能生效?

提前謝謝了!

卡德里

幾年前在Scott Hanselman的博客中 ,您應該嘗試以下操作:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="Redirect to HTTPS" stopProcessing="true">
                    <match url="(.*)" />
                    <conditions>
                        <add input="{HTTPS}" pattern="^OFF$" />
                    </conditions>
                    <action type="Redirect" url="https://{HTTP_HOST}/{R:0}" redirectType="Permanent" />
                </rule>
                </rules>
            </rewrite>
    </system.webServer>
</configuration>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM