IIS7或.Net 301从一个域重定向到另一个域 [英] IIS7 or .Net 301 Redirects from 1 domain to another

查看:61
本文介绍了IIS7或.Net 301从一个域重定向到另一个域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2个域.对于这个问题,我将其称为www.old.com和www.new.com.这两个URL都指向相同的IIS7站点实例.我需要进行调整,以便当有人访问www.old.com时,他们获得301重定向到www.new.com.

棘手的部分是我正在对网站内的页面使用URL重写.因此www.old.com/About.aspx重定向到www.new.com/About.为了使它能够与IIS7 URL重写规则一起使用,还意味着www.new.com/About.aspx重定向到www.new.com/About.很好,没什么大不了的.

我的问题是如何在不丢失子页面的URL重写的情况下重定向主域?

我不在乎是在IIS7中使用模块还是在.NET代码中使用它.

解决方案

我想我会使用重写模块来进行类似的事情. 基本上是说,如果不转到您的新域,则将其重定向到它. 传递其余的网址,这些网址将由您的自定义重写模块

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

希望有帮助!

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.

解决方案

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!

这篇关于IIS7或.Net 301从一个域重定向到另一个域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆