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...


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?

LVL 16
Greg BessoIT Solutions EngineerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dan McFaddenSystems EngineerCommented:
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 EngineerAuthor Commented:
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 :-)
Dan McFaddenSystems EngineerCommented:
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.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Greg BessoIT Solutions EngineerAuthor Commented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft IIS Web Server

From novice to tech pro — start learning today.