簡體   English   中英

IIS 7.5 URL重寫:從舊域到新域的重定向規則似乎不起作用

[英]IIS 7.5 URL Rewrite: Redirect Rule does not appear to work from old domain to new domain

我試圖理解為什么當有人嘗試進入站點時在IIS中創建的以下規則不起作用。

基本上,我們有一個舊域和一個新域。 我希望將所有轉到舊域的人重定向到我們新域上的登錄頁面。

我正在該站點上使用ASP MVC4,並且已經為域添加了綁定並更新了DNS。

我的規則是:

               <rule name="http://www.olddomain.com to landing page" patternSyntax="Wildcard" stopProcessing="true">
                <match url="*" />
                <action type="Redirect" url="http://www.new-domain.co.uk/LandingPage" />
                <conditions logicalGrouping="MatchAny">
                    <add input="{HTTP_HOST}" pattern="http://www.olddomain.com" />
                    <add input="{HTTP_HOST}" pattern="http://olddomain.com" />
                    <add input="{HTTP_HOST}" pattern="http://www.olddomain.com/" />
                    <add input="{HTTP_HOST}" pattern="http://olddomain.com/" />
                </conditions>
            </rule> 

目前,如果有人輸入舊域地址,則重定向不會執行任何操作,該網站就像您通過新域進入首頁一樣,將被加載。

有人可以告訴我我要去哪里錯嗎?

更新下面提供的規則似乎仍然不起作用,因此我決定嘗試在提琴手中打開我的舊域地址,看看是否可以看到重定向或響應。 我得到的只是一個200 HTTP響應,僅此而已。 這使我認為重寫規則實際上被忽略了,但是我不知道為什么。

{HTTP_HOST}將始終只是主機名,並且不包括協議或路徑。 嘗試將規則更改為此:

<rule name="http://www.olddomain.com to landing page" patternSyntax="Wildcard" stopProcessing="true">
    <match url="*" />
    <action type="Redirect" url="http://www.new-domain.co.uk/LandingPage" />
    <conditions logicalGrouping="MatchAny">
        <add input="{HTTP_HOST}" pattern="^www\.olddomain\.com$" />
        <add input="{HTTP_HOST}" pattern="^olddomain\.com$" />
    </conditions>
</rule> 

我為此奮斗了幾天。 我嘗試的10-20重寫規則和失敗原因是:

  1. 如果您嘗試在VisualStudio(2012/2013/2015)中進行重定向,則它無法在實際的IIS托管站點中工作,因為VS在調試時(在項目屬性中指定時)會生成自己的證書,而VS會注意權限問題。
  2. IIS中的站點應該具有有效的證書(沒有從啟用thawte / verisign的網站粘貼文件的副本,甚至沒有由snk.exe生成的自簽名)證書; 請不要以為沒有有效證書就可以。 (在IIS 8和10中自簽名(也稱為開發證書)對我有用;購買的和自簽名之間的區別在這里https://www.sslshopper.com/article-how-to-create-a-self-signed -certificate-in-iis-7.html )。 該證書應安裝,因為IIS可以具有多個證書,但是每個網站都應使用其自己的單獨證書。
  3. 網站綁定應同時具有http(80)和https(443)
  4. 現在重定向語法出現了。 互聯網上有幾個; 您可以輕松獲得正確的正則表達式
  5. 故事的另一面也必須考慮使用MVC 4/5中的Global.asax-> Application_BeginRequest或ActionFilter可以處理重定向。 使用config或以編程方式進行重定向會導致不同的錯誤(在web.config中為TOO_MANY_REDIRECTS)
  6. 我面臨的另一個陷阱是從http-> https重定向可以正常工作,但是我無法從https-> http恢復。
  7. 考慮您的方案(通常不應該混用)

HttpRedirect:

Request 1 (from client):    Get file.htm
Response 1 (from server): The file is moved, please request the file newFileName.htm
Request 2 (from client):    Get newFileName.htm
Response 2 (from server): Here is the content of newFileName.htm

UrlRewrite:

Request 1 (from client):     Get file.htm
URL Rewriting (on server):   Translate the URL file.htm to file.asp
Web application (on server): Process the request (run any code in file.asp)
Response 1 (from server):    Here is the content of file.htm (note that the client does not know that this is the content of file.asp)
whether you need HttpRedirect or UrlRewrite
https://weblogs.asp.net/owscott/rewrite-vs-redirect-what-s-the-difference

暫無
暫無

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

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