Reputation: 2002
I am trying to understand why the following rule created in IIS is not working when a person tries to enter the site.
Basically we have an old domain and a new domain. I would like anyone going to the old domain to be redirected to a landing page on our new domain.
I am using ASP MVC4 for the site and I have added bindings for the domains and updated DNS as well.
My rule is:
<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>
At the moment if someone enters the old domain address the redirect does not do anything, the website just loads as if you were entering via the new domain to the home page.
Can someone tell me where I am going wrong here?
UPDATE The rule provided below still does not seem to work so I decided to just try and open my olddomain address in fiddler to see if I could see the redirect or response. All I get is a 200 HTTP response and nothing more. This makes me think that the rewrite rules are actually being ignored but I have no idea why.
Upvotes: 1
Views: 1851
Reputation: 1725
I had struggled on this for several days. 10-20 rewrite rule I tried and reasons of failure are:
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
Upvotes: 0
Reputation: 141638
{HTTP_HOST}
will always just be the host name, and not include the protocol or path. Try changing your rule to this:
<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>
Upvotes: 2