Bulk 301 Redirects?
# help-with-umbraco
o
Hi All! Just wondering if there is a way to bulk upload 301 redirects. A client of mine has recently migrated to a new website and I am trying to setup 301 Redirects in the new site from old URLs.
m
if you don't need them in the backoffice in any way you can set up an iRule or if a simple regexp redirect would work just a redirect?
Copy code
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
    var rewriteOptions = new RewriteOptions()
        
        .AddRedirect("^news-story/(.*)$", "/news/$1", StatusCodes.Status301MovedPermanently)
...
}
https://learn.microsoft.com/en-us/aspnet/core/fundamentals/url-rewriting?view=aspnetcore-7.0#irule-based-rule
You can also just use old style IIS rewrite rules from a web.config file and a rewrite map? If you are hosting on IIS.. if you want Kestrel to also see them.. https://learn.microsoft.com/en-us/aspnet/core/fundamentals/url-rewriting?view=aspnetcore-7.0#iis-url-rewrite-module-rules
For adding to the Umbraco inbuilt url redirection.. then I think it just stores in the
[umbracoRedirectUrl]
table
o
Its pretty much down to which fits best for SEO best practice
m
so that would exclude urlAlias.. but any of the other approaches gets you a 301 from the old url to the new one and SEO would be happy..
There's a couple of packages too.. https://marketplace.umbraco.com/search/redirect
o
Thanks for this information, had a developer tell me it wasnt doable on his end, seems like it absolutely is.
d
If you have a lot of redirects and are using IIS then you can put them in an XML file and then use that. You just need to register it in the Umbraco
startup.cs
file:
app.UseRewriter(new RewriteOptions().AddIISUrlRewrite(env.ContentRootFileProvider, "IISUrlRewrite.xml"));
https://learn.microsoft.com/en-us/aspnet/core/fundamentals/url-rewriting?view=aspnetcore-7.0
m
My understanding is that if you aren't using IIS then you need to do that eg aspnetcore process then takes care of it in the middleware, if you are using IIS then no need to do that, you can just add a web.config using the rewritemaps approach..
Copy code
<system.webServer>
  <rewrite>
    <rules>
      <rule name="Rewrite Rule">
        <match url=".*" />
        <conditions>
            <add input="{StaticRewrites:{REQUEST_URI}}" pattern="(.+)" />
        </conditions>
        <action type="Rewrite" url="{C:1}" />
    </rule>
    </rules>
    <rewriteMaps>
        <rewriteMap name="StaticRewrites">
            <add key="{OLD}" value="{NEW}" />
        </rewriteMap>
  </rewrite>
</system.webServer>
and IIS will handle the redirects natively before the aspnet process gets involved, with improved performance.. Inded the MS docs actually advise you only to use UseRewriter if you can't use IIS native. https://learn.microsoft.com/en-us/aspnet/core/fundamentals/url-rewriting?view=aspnetcore-7.0#when-to-use-url-rewriting-middleware
Copy code
Use URL Rewriting Middleware when the following approaches aren't satisfactory:

- URL Rewrite module with IIS on Windows Server
- Apache mod_rewrite module on Apache Server
- URL rewriting on Nginx
2 Views