Redirect a list of URLs in Web.Config










0















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?










share|improve this question






















  • 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
    Nov 13 '18 at 13:27















0















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?










share|improve this question






















  • 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
    Nov 13 '18 at 13:27













0












0








0








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?










share|improve this question














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?







iis web-config url-redirection






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 13 '18 at 6:09









John GreenJohn Green

11.2k21948




11.2k21948












  • 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
    Nov 13 '18 at 13:27

















  • 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
    Nov 13 '18 at 13:27
















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
Nov 13 '18 at 13:27





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
Nov 13 '18 at 13:27












1 Answer
1






active

oldest

votes


















0














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






share|improve this answer























  • Thanks. Not so much worried about the spreadsheet part -- more about the right way to create the redirects. So far, it looks like individual rules as you show above or a rewriteMap that gets pulled into a redirect rule. I was able to cobble together what appears to be the appropriate structure for a rewriteMap. I think my main problem is that I have found the documentation does not really address this simple case very well / or in a straightforward manner, especially for somebody who doesn't typically work with IIS, which is why Google wasn't helping me much.

    – John Green
    Nov 14 '18 at 23:54










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53274825%2fredirect-a-list-of-urls-in-web-config%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














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






share|improve this answer























  • Thanks. Not so much worried about the spreadsheet part -- more about the right way to create the redirects. So far, it looks like individual rules as you show above or a rewriteMap that gets pulled into a redirect rule. I was able to cobble together what appears to be the appropriate structure for a rewriteMap. I think my main problem is that I have found the documentation does not really address this simple case very well / or in a straightforward manner, especially for somebody who doesn't typically work with IIS, which is why Google wasn't helping me much.

    – John Green
    Nov 14 '18 at 23:54















0














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






share|improve this answer























  • Thanks. Not so much worried about the spreadsheet part -- more about the right way to create the redirects. So far, it looks like individual rules as you show above or a rewriteMap that gets pulled into a redirect rule. I was able to cobble together what appears to be the appropriate structure for a rewriteMap. I think my main problem is that I have found the documentation does not really address this simple case very well / or in a straightforward manner, especially for somebody who doesn't typically work with IIS, which is why Google wasn't helping me much.

    – John Green
    Nov 14 '18 at 23:54













0












0








0







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






share|improve this answer













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







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 14 '18 at 22:37









MisterSmithMisterSmith

948611




948611












  • Thanks. Not so much worried about the spreadsheet part -- more about the right way to create the redirects. So far, it looks like individual rules as you show above or a rewriteMap that gets pulled into a redirect rule. I was able to cobble together what appears to be the appropriate structure for a rewriteMap. I think my main problem is that I have found the documentation does not really address this simple case very well / or in a straightforward manner, especially for somebody who doesn't typically work with IIS, which is why Google wasn't helping me much.

    – John Green
    Nov 14 '18 at 23:54

















  • Thanks. Not so much worried about the spreadsheet part -- more about the right way to create the redirects. So far, it looks like individual rules as you show above or a rewriteMap that gets pulled into a redirect rule. I was able to cobble together what appears to be the appropriate structure for a rewriteMap. I think my main problem is that I have found the documentation does not really address this simple case very well / or in a straightforward manner, especially for somebody who doesn't typically work with IIS, which is why Google wasn't helping me much.

    – John Green
    Nov 14 '18 at 23:54
















Thanks. Not so much worried about the spreadsheet part -- more about the right way to create the redirects. So far, it looks like individual rules as you show above or a rewriteMap that gets pulled into a redirect rule. I was able to cobble together what appears to be the appropriate structure for a rewriteMap. I think my main problem is that I have found the documentation does not really address this simple case very well / or in a straightforward manner, especially for somebody who doesn't typically work with IIS, which is why Google wasn't helping me much.

– John Green
Nov 14 '18 at 23:54





Thanks. Not so much worried about the spreadsheet part -- more about the right way to create the redirects. So far, it looks like individual rules as you show above or a rewriteMap that gets pulled into a redirect rule. I was able to cobble together what appears to be the appropriate structure for a rewriteMap. I think my main problem is that I have found the documentation does not really address this simple case very well / or in a straightforward manner, especially for somebody who doesn't typically work with IIS, which is why Google wasn't helping me much.

– John Green
Nov 14 '18 at 23:54

















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53274825%2fredirect-a-list-of-urls-in-web-config%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

How to read a connectionString WITH PROVIDER in .NET Core?

Node.js Script on GitHub Pages or Amazon S3

Museum of Modern and Contemporary Art of Trento and Rovereto