Adding "virtual" virtual directories on every site/level on IIS

Vita 76 Reputation points
2022-09-09T07:22:38.033+00:00

I want to make available a directory, say "/assests/", only less generic to every site at every level, even it the parent directory specified doesn't exist — I'm moving to IIS from Apache httpd where I had this setup.

Adding "real" virtual directories not only would be impractical but also impossible so I'm following the same approach I had on httpd; mod_rewrite, its IIS equivalent.

"/assets/" is a directory on its own site, e.g. "assetssite.domain.tld/assets". So I figured I just had to match "asssets/" whatever follows it, what precedes it and replace.

Using regex, I tried: "[ ^(http|https)(://./)(assets/)(.) ]" which would be rewritten "[ {R:1}://assetssite.domain.tld/{R:3}{R:4} ]". Right after I read on the docs that at the server level, only the path is considered, so I tried again with a simpler "[ (./assets/)(.) ]", rewritten: "[ http://assetssite.domain.tld/assets/{R:2} ]" but it didn't work.

I'm thinking maybe I need ARR because this is basically proxying but I'm not sure, the documentation is all over the place. How can I set this up? Is URL Rewrite enough? --- thanks!

Internet Information Services
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Yurong Dai-MSFT 2,796 Reputation points Microsoft Vendor
    2022-09-09T09:27:31.553+00:00

    Hi @Vita ,
    What I don't understand is what you're saying about adding "virtual" virtual directories on every site/level has anything to do with your rewrite rules?

    But according to your rewrite rules, you need to enable ARR on server.
    239454-image.png

    Then try this: (.*)assets(.*) rewritten: http://assetssite.domain.tld/assets/{R:2}
    239405-image.png

    If your rewrite rules don't work, it's probably because it doesn't match the pattern successfully. I suggest you enable FRT, please refer to this link. FRT can be used with the URL Rewrite module to track how rewrite rules are applied to request URLs.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the email notification for this thread.

    Best regards,
    Yurong Dai


  2. Vita 76 Reputation points
    2022-09-12T01:37:38.833+00:00

    I'm writing this as an answer to my own question: if you're planning on using IIS as a proxy, even to itself, don't.

    Adding a URL Rewrite rule at the server level would be the best place to switch the hostname, unfortunately it doesn't consider the hostname at all which is beyond moronic. That is the place where it should be considered.

    You might argue, so what? I'm only interested in the path anyway Good point. But, what if one of your sites matches the rewritten hostname? Without being able to act on the hostname to negate it with a regex, eg;

       ^((http:\/\/|https:\/\/)(?!assetssite.domain.tld)(.*)(assets\/))(.*)$  
    
       {R:2}assetssite.domain.tld{R:4}{R:5}  
    

    --- where ---
    R1 is the scheme, either "https://" or "http://"
    (http://|https://)

    R2 the negated
    !?
    =notMatchWhatsComing (AKA negative lookahead) hostname so traffic go straight through a page or something on it was actually requested
    (?!assetssite.domain.tld)

    R3 whatever
    (.*)

    R4 key directory
    (assets/)

    R5 whatever after it 'till the end
    (.*)
    ,
    $

    You're forced to do something lke
    (.)(assets/))(.)$

    straight to the path or remove the hostname from the site and proxy to a port number or some other already too complex configuration. Because this is not technically IIS but IIS modules, it's not in the main documentation--not that it would be less confusing--but spread around in multiple places.

    Then there's the diagnostics of things. It's insane, it takes more work to set up that just going through every possible scenario imaginable. Furthermore, you need to catch this files quickly. If you have an actual competent proxy already set up pointing to this server, performing health checks, these files would just fly by, as each health check would create a new one.
    It's not clear what happens to wildcard hostnames.

    IIS is supposed to be the easy web server, I'm paraphrasing. Nothing of this is easy. It's cumbersome and annoying and though doable, it requires too many levels of abstractions because of its lack of common sense. Windows Server Datacenter (bc the other is just a waste of money) is around six grand, this UI has been there forever suggesting none of that price tag is going to product improvement, nor that telemetry we're forced to send. This is outrageous.

    For 200, RHEL does a much better job. Fedora, Ubuntu and Debian, do it for free. All 4 have very good documentation. Another thing missing from Windows.

    RUN AWAY.

    0 comments No comments