IIS7 Rewrite Module - Redirct from root to default.aspx

854 Views Asked by At

I have a situation where I need to rewrite from the root to default.aspx. So if someone hits www.domain.com or www.domain.com/ I need to redirect to www.domain.com/default.aspx - any idea what the regex for this looks like and which server variable to regex on?

When I run a trace and I visit www.domain.com/ or www.domain.com it always shows the SCRIPT_NAME and other similar server variables to have a value of /default.aspx - however this does not work in the rewrite module. E.g. when someone visits www.domain.com/ or www.domain.com the SCRIPT_NAME is still /default.aspx - so it doesn't seem to pick up that they visited the non default.aspx page.

2

There are 2 best solutions below

0
On BEST ANSWER

I solved this by using a Url Rewrite map (part of the rewrite module), I was able to redirect from / to /default.aspx. As a rule before the rewrite map I make sure that all requests are redirected to an ending slash.

1
On

I had a similar problem and I think it really sucks that IIS hides the URL from you and only gives you the name of the script, which you already know. It was worse in earlier versions of IIS, because it forgot to copy the query string. I had to work around that by not defining any default document at all, and making the error page for directory listing denied redirect to the script. I guess the same thing would work here.