Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc 4 IIS 7.5 URL重写:从旧域到新域的重定向规则似乎不起作用_Asp.net Mvc 4_Url_Redirect_Iis_Url Rewrite Module - Fatal编程技术网

Asp.net mvc 4 IIS 7.5 URL重写:从旧域到新域的重定向规则似乎不起作用

Asp.net mvc 4 IIS 7.5 URL重写:从旧域到新域的重定向规则似乎不起作用,asp.net-mvc-4,url,redirect,iis,url-rewrite-module,Asp.net Mvc 4,Url,Redirect,Iis,Url Rewrite Module,我试图理解为什么当一个人试图进入网站时,IIS中创建的以下规则不起作用 基本上我们有一个旧域和一个新域。我想任何人去旧域被重定向到我们的新域上的登录页 我正在为该站点使用ASP MVC4,我已经为域添加了绑定,并更新了DNS 我的规则是: <rule name="http://www.olddomain.com to landing page" patternSyntax="Wildcard" stopProcessing="true">

我试图理解为什么当一个人试图进入网站时,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> 

此时,如果有人输入旧域地址,重定向不会做任何事情,网站只会加载,就像您通过新域进入主页一样

有人能告诉我哪里出了问题吗

更新
下面提供的规则似乎仍然不起作用,所以我决定尝试在fiddler中打开我的olddomain地址,看看是否可以看到重定向或响应。我得到的只是一个200HTTP响应,仅此而已。这让我觉得重写规则实际上被忽略了,但我不知道为什么。

{HTTP\u HOST}
将始终只是主机名,而不包括协议或路径。尝试将规则更改为:


我为此挣扎了好几天。10-20重写规则我尝试过,失败原因如下:

  • 如果您尝试在VisualStudio(2012/2013/2015)中重定向,它将无法在实际的IIS托管站点中工作,因为VS在调试时生成自己的证书(当您在项目属性中指定时),权限问题由VS处理
  • IIS中的站点应具有有效的(没有从启用thawte/verisign的网站复制粘贴文件,甚至没有由snk.exe生成的自签名)证书;请不要以为没有有效的证书你可以。(iis8和iis10中的自签名(也称为devcert)对我有用;购买的和自签名的区别在这里)。应安装证书,因为IIS可以有多个证书,但每个网站都应使用自己的单独证书
  • 站点绑定应该同时具有http(80)和https(443)
  • 现在重定向语法出现在图片中;互联网上有几家;您可以很容易地得到正确的正则表达式
  • 另一方面还必须考虑,重定向可以使用MVC4/5中的Global.asax->Application_BeginRequest或ActionFilter来处理。 使用配置或编程方式执行重定向可能会导致不同的错误(web.config中的重定向太多)
  • 我面临的另一个难题是从http->https重定向工作正常,但我无法从https->http返回
  • 考虑一下您的场景(通常不应该混合在可用选项之外)
  • HttpRedirect: URL重写:
    谢谢你的回复。我刚刚注意到我用HTTP_POST打错了字!谢谢你发现了这一点。然而,这项新规则仍然没有如预期的那样发挥作用。所发生的一切就是站点在其默认页面上打开,而重定向不会发生occur@DavidHirst尝试将匹配URL更改为
    。模式语法使用通配符。删除此属性并使用
    这似乎对我仍然不起作用。请检查我上面的更新。
    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
    
    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