Hiding a Folder In Requests

Topics: Developer Forum, User Forum
Apr 14, 2010 at 1:16 PM


For various reasons I had to add another subfolder for our application.  Originally, our site could be accessed like:


Unfortunately, I had to add another directory like so:


Which is now where the web site resides.  I would like to use rewriting to make the folder disappear, make the user still be able to go to http://www.site.com/default.aspx even though I added this new folder level.

Is that possible?  How do I set that up?


Apr 14, 2010 at 4:10 PM

Sure, that should be fairly trivial.  Do you have something else in your root directory, or is it now empty?  If you don't need anything to go to the root, you could make a simple rule like

RewriteRule ^/(.*) /folder/$1



Apr 14, 2010 at 6:30 PM

Good answer.  Except....

IIRF rewrites iteratively.  After each successful rewrite, IIRF will apply all the rules again, until no rule fires.  So, that rule will fire multiple times,  until IIRF reaches its iteration limit, which I think is set to 8 or 10 by default.   (Can't recall, it's in the doc).

So the result is, if you request   http://server/foo you will get http://server/folder/folder/folder/folder..(8times)../foo   .  Which is probably not what you want.

The way to avoid that is to qualify the rule so that it matches only if folder is not already the first thing in the URL.  Like this:

RewriteRule ^/(?!folder/)(.*) /folder/$1

You could also avoid this by using the [L] modifier on the orignial rule proposed by rswitt.  That prevents the iteration I described.


Apr 14, 2010 at 6:36 PM

ps: Also, you need to be careful of postbacks.  The rule I described will work fine for incoming requests.
but there are some potential pitfalls for ASPX postbacks, like when you submit a form on an ASPNET page.

See this thread for details.

It's not a problem that's particular to IIRF.  Any time you do URL rewrites with ASPNET, then you'll have to be aware of the postback URL issue.


Apr 14, 2010 at 9:01 PM

Regarding my original post, oops!  I totally forgot the [L] flag!  Consider me flogged with a wet noodle ;-).


Apr 15, 2010 at 5:41 PM

Thanks, that worked.. I am experiencing that issue regarding postbacks and using Response.Redirect too...  will check that post.