繁体   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