簡體   English   中英

阻止無效的URL並重定向到IIS中的主頁

[英]Blocking invalid URL and redirect to homepage in IIS

目前,我正在使用另一家公司提供的網絡托管服務。 它使用IIS 7 / IIS 8,並允許客戶根據需要修改web.config

假設我設置了兩個有效的URL:

  1. http://www.example.com
  2. http://dev.example.com

現在,當我嘗試訪問http://abc.example.com ,返回HTTP Error 403.14 - Forbidden訪問; 並且如果我隨后嘗試訪問http://www.example.com/abc ,則返回HTTP Error 404.0 - Not Found

我如何配置web.config ,以便在嘗試訪問無效URL時將用戶重定向到http://www.example.com

我嘗試使用公司提供的代碼段,但未成功:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="Canonical Host Name" stopProcessing="true">
                  <match url="(.*)" />
                  <conditions>
                    <add input="{HTTP_HOST}" pattern="^example\.com$" />
                  </conditions>
                  <action type="Redirect" url="http://www.example.com/{R:1}" redirectType="Permanent" />
                </rule>
             </rules>
        </rewrite>
    </system.webServer>
</configuration>

在system.web中的webconfig標簽中添加此標簽

<customErrors mode="On" defaultRedirect="~/Home/Index"> 
 </customErrors>

每當發生錯誤時,這會將您重定向到主頁。您可以通過添加customErrors標記來更詳細地重定向

<error statusCode="401" redirect="/error/otherpage"/>

這將指示發生401錯誤時將您重定向到的頁面

暫無
暫無

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

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