I have a domain say www.mydomain.com and want to 301 redirect anything at that domain to my domain alias which is say www.mydomainalias.com. So the following will be true:
Thanks Jeff, you set me on the right path, however it still does not seem to redirect and I am sure I have the correct rule and regular expression. I used the test pattern in "Edit Inbound Rule" and it worked on all scenarios. This is what I ended up with:
At the moment I only have 2 files in my root (web.config and index.html). It should look at the web.config before any other file shouldn't it. I shouldn't need any other files in there should I?
Actually, the domain name information is not included inside the input url. You need to capture the domain name with "HTTP_HOST" server varuable in condition:
Inology
3 Posts
Rule to redirect to domain alias
Jan 05, 2012 07:03 AM|LINK
Hi,
I have a domain say www.mydomain.com and want to 301 redirect anything at that domain to my domain alias which is say www.mydomainalias.com. So the following will be true:
I have attempted to write an URL Rewrite Rule for it with no success as follows:
<
rewrite><rules>
<rule name="Domain Redirect" enabled="true" stopProcessing="true">
<match url="^(www.)?mydomain\.com\.au/" />
<action type="Redirect" url="www.mydomainalias.com.au/" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
I am sure it is not that hard. Your help would be appreciated.
Thanks, John
URL Rewrite url redirect 301 permanent redirect url rewrite inbound rule domain alias
jeff@zina.co...
3379 Posts
MVP
Moderator
Re: Rule to redirect to domain alias
Jan 05, 2012 01:30 PM|LINK
How about:
<rewrite>
<rules>
<rule name="Domain Redirect" stopProcessing="true">
<match url="^mydomain.com.au/([0-9]+)/([_0-9a-z-]+)" />
<action type="Redirect" url="mydomain.com/{R:1}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
From scratch, untested. If it doesn't work with a little tweaking, try a rewrite map as per:
http://learn.iis.net/page.aspx/469/using-rewrite-maps-in-url-rewrite-module/
Jeff
Inology
3 Posts
Re: Rule to redirect to domain alias
Jan 05, 2012 10:46 PM|LINK
Thanks Jeff, you set me on the right path, however it still does not seem to redirect and I am sure I have the correct rule and regular expression. I used the test pattern in "Edit Inbound Rule" and it worked on all scenarios. This is what I ended up with:
<
rewrite><rules>
<rule name="Domain Redirect" stopProcessing="true">
<match url="^(www.)?mydomain.com.au/([/_0-9a-z-.]+)?" />
<action type="Redirect" url="www.mydomainalias.com.au/{R:2}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
At the moment I only have 2 files in my root (web.config and index.html). It should look at the web.config before any other file shouldn't it. I shouldn't need any other files in there should I?
John
Edit Inbound Rule
Lloydz
2335 Posts
Microsoft
Re: Rule to redirect to domain alias
Jan 09, 2012 02:06 AM|LINK
Hi,
Actually, the domain name information is not included inside the input url. You need to capture the domain name with "HTTP_HOST" server varuable in condition:
<rule name="Domain Redirect" stopProcessing="true">
<match url="(.*)" />
<action type="Redirect" url="http://{C:1}mydomainalias.com.au/{R:1}" redirectType="Permanent" />
<conditions>
<add input="{HTTP_HOST}" pattern="^(www\.)?mydomain\.com\.au" />
</conditions>
</rule>
Let me know if you are still facing any issues on this task.
Thanks.
Inology
3 Posts
Re: Rule to redirect to domain alias
Jan 09, 2012 09:32 PM|LINK
Thank you Lloydz, that did the trick... I really appreciate your help... Have a great day :)
John