将旧域重定向到新域名保留URL [英] Redirect old domain to new domain keeping url

查看:256
本文介绍了将旧域重定向到新域名保留URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在发布我们的Web应用程序的新版本,并在进行品牌改动的过程中也使用新的域名。



我们的所有应用程序都托管在Azure中。
当前应用程序 - 云服务
新应用程序 - Azure网站



我想要实现的是将旧域中的任何旧链接重定向到新的域名保留url部分。



示例:
用户访问
https://my.currentdomain.com/any/link



,并将被定向到
https://my.newdomain.io/any/link



我是从C#到现在的域名,然后在我的web.config中重写一个URL。



谢谢!



更新 - 我已经在本地进行了测试,并且它正在寻找。我只是将旧域名的cname指向新的域名,这个重定向应该可以接收链接。

  rule name =重定向到新域stopProcessing =true> 
< match url =^(。*)$/>
<条件>
< add input ={HTTP_HOST}matchType =Patternpattern =^ olddomain(:\d +)?$/>
< / conditions>
< action type =Redirecturl =https://my.newdomain.io/{R:1}redirectType =Permanent/>
< / rule>


解决方案

在Azure中托管您的应用程序的事实很少对您将要找到的解决方案没有任何影响。



当您执行此类操作时,您通常还要保留您在搜索引擎中的所有积分。而您只能实现这一点,如果您的 https://my.current.domain.com/any/link 执行 HTTP 301重定向永久到新的位置。



根据您的项目的大小和复杂性,这可能是一个微不足道的任务或不那么容易。



一个选项,仅当您要重定向几个(如十几个)链接时才有效。您可以直接在Web.Config文件中执行此操作:

 < location path =any / link> 
< system.webServer>
< httpRedirect enabled =truedestination =https://my.newdomain.io/any/linkhttpResponseStatus =Permanent/>
< /system.webServer>
< / location>

当你有一堆链接,甚至整个CMS后面的这个当然没有意义场景。如果是这种情况,我会选择加入 IIS的自定义HTTP模块。该模块的唯一目的是检查传入的URI,并进一步提供,或者生成HTTP 301重定向。



如果您使用的是最新的和最大的Microsoft ,可以使用自定义OWIN(自定义HTTP模块)实现相同的(自定义HTTP模块)中间件



如果只是域更改,所有路径和查询字符串都将被保留,请查看这个好的文章你可以如何使用IIS下的URL Rewrite来实现这一点。 / p>

We are releasing a new version of our Web app and in the process doing a branding change with a new domain also.

Both our apps are hosted in Azure. Current App - Cloud Service New App - Azure Website

What I want to achieve is redirect any old links from the old domain to the new domain while keeping the url portion.

Example: User visits https://my.currentdomain.com/any/link

and will be directed to https://my.newdomain.io/any/link

Do I do a CNAME from currentdomain to newdomain and then a URL Rewrite in my web.config??

Thanks!

Update - I've test this locally and it does what I'm looking for. I'll just point the cname of the old domain to the new domain and this redirect should pick up the links.

<rule name="Redirect to new domain" stopProcessing="true">
      <match url="^(.*)$" />
      <conditions>            
        <add input="{HTTP_HOST}" matchType="Pattern" pattern="^olddomain(:\d+)?$" />
      </conditions>
      <action type="Redirect" url="https://my.newdomain.io/{R:1}" redirectType="Permanent" />
    </rule>

解决方案

The fact that you host your application in Azure has minimal to no impact on the solution you are going to find.

When you do such things, you usually want to also keep all the credits that you have in the search engines. And you can only achieve that if your https://my.current.domain.com/any/link does a HTTP 301 Redirect Permanent to the new location.

Depending on the size and complexity of your project this can be a trivial task or not so easy.

One option, which is valid only if you want to redirect few (like a dozen) links. You can do that directly in your Web.Config file:

  <location path="any/link">
    <system.webServer>
      <httpRedirect enabled="true" destination="https://my.newdomain.io/any/link" httpResponseStatus="Permanent" />
    </system.webServer>
  </location>

This of course makes no sense when you have a bunch of links, or even a whole CMS behind the scenes. If this is the case, I would opt-in for writing a custom HTTP Module for IIS. This module will have the sole purpose of inspecting the incoming URI and either let it further, or generate HTTP 301 redirect.

If you are using the latest and the greatest from Microsoft, the same (custom HTTP Module) can be achieved with a custom OWIN Middleware.

If it is just domain change, all paths and query strings are to be kept, check out this good article how can you do this with URL Rewrite under IIS.

这篇关于将旧域重定向到新域名保留URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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