0
votes

I have a list of URLs, some of which are offsite, for a site platform transition. I have a one:one mapping of these in a spreadsheet, and need to do a 301 redirect from old URL to new URL.

e.g. /foo (living on https://oldsite.com) to https://newsite.com/some_promo

After an hour of googling, I've found some lots of ways to do fancy, eloquent things in web.config, but all I really need is a hammer and am happy to brute force the thing.

What's the best way to simply issue 301 redirects from URL1 to URL2 from a list of ~200 URLs?

1
Write a script to convert your spreadsheet to a rewrite map docs.microsoft.com/en-us/iis/extensions/url-rewrite-module/… and then IIS URL Rewrite module can be used.Lex Li

1 Answers

0
votes

I dunno about "best" way, this is certainly "a way"...

Assuming you have a spreadsheet with 2 columns - column 'A' contains hte old url as a relative path, column 'B' contains the fully qualified destination url - you should be able to use the spreadsheets concatenation function (ive done this for nginx rewrites, but it should work for IIS) to assemble the redirects, then copy and paste them into the web.config.

Start with a simple rewrite

<rule name="Redirect 1" stopProcessing="true">
     <match url="/source.html" />
     <action type="Redirect" url="https://www.example.com/destination.html" />
</rule>

(you will need to "flatten" it into a single line first)

Split the rule into 4 parts <rule name="Redirect, " stopProcessing...url=", " />...url=" and finally " /></rule> (ie leave space to number the rule, and remove the source and destination urls), and paste these 4 fragments into cells E1, F1, G1 and H1 in the sheet. In Column 'C' enter numbers 1..200 (rules need unique names), then in Column 'D', (in Excel at least) enter

=CONCAT(E$1,C1,F$1,A1,G$1,B1,H$1)

(E$1 .. H$1 are the 4 cells that contain the fragments - the $ is to stop Excel from incrementing the rows).

Copy that formula down the page - volia