IIS7 or .Net 301 Redirects from 1 domain to another

柔情痞子 提交于 2019-12-10 10:48:09

问题


I have 2 domains. For the question, I will call them www.old.com and www.new.com. Both urls are pointing to the same IIS7 Site instance. I need to it up so that when someone goes to www.old.com they get a 301 redirect to www.new.com.

The tricky part is I am using URL rewrites for pages within the site. So www.old.com/About.aspx redirects to www.new.com/About. To get that to work with IIS7 URL rewrite rules, it also means that www.new.com/About.aspx redirects to www.new.com/About. That is fine and is not a big deal.

My issue is how do I redirect the main domain without losing the URL Rewrites from the sub pages?

I don't care if I use a module within IIS7 or if I need to do it in .NET code.


回答1:


I think I would go for something like this using a rewrite module. Basically is saying that if is not going to your new domain then redirect it to it. passing the rest of the url that will by your custom rewrite module

 <rewrite>
        <rules>
            <rule name="CustomRule">
                <match url="(.*)" />
                <conditions>
                    <add input="{HTTP_HOST}" pattern="^www\.new\.com$" negate="true" />
                </conditions>
                <action type="Redirect" url="http://www.new.com/{R:1}" />
            </rule>
        </rules>
    </rewrite>

Hope it helps!



来源:https://stackoverflow.com/questions/3046081/iis7-or-net-301-redirects-from-1-domain-to-another

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!