Avatar of Greg Besso
Greg BessoFlag for United States of America

asked on 

IIS redirect question - capturing all subdirectories requests, sending to a root page to process, then forward on...

Hi all,

This might be a simple one, but I am not familiar how to accomplish this in IIS. I want to accept all incoming requests for a site, say the following...

http://thesitesOldName.domain.local
http://thesitesOldName.domain.local/someFolder/somePage
http://thesitesOldName.domain.local/someOtherFolder/pageThatDoesntExistAnyMore.action?pageId=1234567

So I'd like these different types of URLs all to somehow be caught by IIS and just forward the URL to a new root page like default.aspx and then I'll mince it up and forward to the page of my choosing later. But I don't want to put subfolders with catch all pages since I don't know the list of all the subfolders. The old site URLs are going to be forwarded to this IIS temp server to handle redirection with a nice little 5 second notice to users. Otherwise we'd just handle it on the load balancer/firewall.

Any suggestions?

Thanks,
Greg
Microsoft IIS Web ServerC#ASP.NET

Avatar of undefined
Last Comment
Greg Besso
Avatar of Dan McFadden
Dan McFadden
Flag of United States of America image

You can use the IIS URL Rewrite feature to handle this functionality.

Link: http://www.iis.net/downloads/microsoft/url-rewrite

Here is an article that has an example of what you are trying to accomplish.

Link:  https://mlichtenberg.wordpress.com/2014/11/11/iis-url-rewrite-directing-all-traffic-to-the-site-root/

Dan
Avatar of Greg Besso
Greg Besso
Flag of United States of America image

ASKER

It probably was not the best way to do this, but I ended up using the IIS > Error Pages at the site level. I edited the 404 item to "execute a URL on this site", linked to a new /customError.aspx page that I put in the site...

Then within that new file I did something like this...

string getURL = Request.Url.AbsoluteUri;
string[] getOldURL;
string getNewURL = "";
char[] separatorsURL2 = { ';' };
getOldURL = getURL.Split(separatorsURL2);
if (getOldURL.Length > 1) {
            getNewURL = getOldURL[1].Replace(getHOST,"new.domain.com");
      } else {
            getNewURL = getOldURL[0].Replace(getHOST,"new.domain.com");
            getURL = getURL.Replace("/customError.aspx","");
            getNewURL = getNewURL.Replace("/customError.aspx","");
      }

Then I passed that to JavaScript to redirect...

Response.Write("<script language='JavaScript'>");
            Response.Write("setTimeout(function(){");
            Response.Write("document.location = '" + getNewURL + "';");
            Response.Write("}, 7000);");
      Response.Write("</script>");

Got sidetracked sorry for lack of response earlier :-)
ASKER CERTIFIED SOLUTION
Avatar of Dan McFadden
Dan McFadden
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Greg Besso
Greg Besso
Flag of United States of America image

ASKER

Oh I think for two reasons:

1) I honestly didn't now any better :P
2) I wanted the redirect to have a brief notification page so then the user was shown the new URL, before being sent to it. Kind of so they may update their bookmarks and we can shed the old URL support.

But yah mostly because of #1 :P
ASP.NET
ASP.NET

The successor to Active Server Pages, ASP.NET websites utilize the .NET framework to produce dynamic, data and content-driven web applications and services. ASP.NET code can be written using any .NET supported language. As of 2009, ASP.NET can also apply the Model-View-Controller (MVC) pattern to web applications

128K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo