简体   繁体   English

大数据的asp.net 301重定向

[英]asp.net 301 redirect for big data

I have changed my website database, and i have more than 10000 url has been changed, and i need to do 301 redirect, what is best way to handle that big amount of data as 301 redirect ?我更改了我的网站数据库,并且更改了 10000 多个 url,我需要执行 301 重定向,处理 301 重定向这样大量数据的最佳方法是什么?

i cannt do it by using web.config, the file will became very big, and it will take much effort用web.config不行,文件会很大,费很大力气

<httpRedirect enabled="true" exactDestination="true" httpResponseStatus="Permanent">
     <add wildcard="/MyOldAspFile.aspx" destination="/MyNewFile.aspx" />
     <add wildcard="/MyOldHtmlFile.html" destination="/MyNewFile.aspx" />
</httpRedirect>

so, what is the best way to handle that case ?那么,处理这种情况的最佳方法是什么?

I want to recommend to use rewrite maps for that purpose.我想建议为此目的使用重写映射。 And store rewrite map in another file.并将重写映射存储在另一个文件中。 In your web.config it will be:在您的 web.config 中,它将是:

<rewrite>
  <rewriteMaps configSource="rewriteMaps.config"/>
  <rules configSource="rewriteRules.config"/>
</rewrite>

In your rewriteRules.config;在你的 rewriteRules.config 中;

<rules>
   <rule name="Rule for Redirects">
      <match url=".*" />
      <conditions>
         <add input="{Redirects:{REQUEST_URI}}" pattern="(.+)" />
      </conditions>
      <action type="Redirect" url="{C:1}" appendQueryString="false" />
   </rule>
</rules>

In your rewriteMaps.config:在你的 rewriteMaps.config 中:

<rewriteMaps>
    <rewriteMap name="Redirects">
        <add key="/old1" value="/new1" />
        <add key="/old2" value="/new2" />
     </rewriteMap>
</rewriteMaps>

And URL Rewrite Module should be installed in your IIS并且 URL 重写模块应该安装在你的 IIS 中

You can fill rewriteMaps programmatically, if you have DB with old urls.如果您有带有旧网址的数据库,您可以以编程方式填充 rewriteMaps。 Sample of simple logic is here:简单逻辑示例在这里:

var urls = new Dictionary<string, string>();
urls.Add("/old", "/new");

var lines = new List<string>();

lines.Add("<rewriteMaps>");
lines.Add("<rewriteMap name=\"Redirects\">");

foreach (var url in urls)
{
    lines.Add(string.Format("<add key=\"{0}\" value=\"{1}\" />", url.Key, url.Value));
}

lines.Add("</rewriteMap>");
lines.Add("</rewriteMaps>");

System.IO.File.WriteAllLines(@"rewriteMaps.config", lines);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM