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

Greg Besso
Greg Besso used Ask the Experts™
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...


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?

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Dan McFaddenSystems Engineer

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/

Greg BessoIT Solutions Engineer


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("document.location = '" + getNewURL + "';");
            Response.Write("}, 7000);");

Got sidetracked sorry for lack of response earlier :-)
Systems Engineer
Why the double hop?  You can do the redirect in ASP.NET.


Reference: https://support.microsoft.com/en-us/kb/312063


Reference: https://msdn.microsoft.com/en-us/library/t9dwyts4%28v=vs.110%29.aspx?cs-save-lang=1&cs-lang=vb#code-snippet-1

The method is fine.  There is often more than one way to solve an issue.

Greg BessoIT Solutions Engineer


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

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial