Score:0

IIS websites in subdirectory => HTML source requests to root "/" points to default website instead of subdirectory

ph flag

Our IIS hosts our own website. But recently we have been tasked with hosting a third party website built using Laravel in a subdirectory.

The website is loading, but most of the resources like CSS and JS files are not being loaded (404) because of the way the third-party site requests it's resources. E.g:

<script source="/js/site.js"></script>

/js/site.js translates to https://defaultwebsite/js/site.js which doesn't exist. I need /js/site.js to translates to https://defaultwebsite/laravel/public/js/site.js.

Is this possible in IIS 10?

Here's a sketch of the directory tree:

+ defaultwebsite
| + laravel
| | + public
| | | + js
| | | | - site.js
| | | - index.php
| + js
| | - ourownjs.js
| - index.php

We have two rewrite rules set up to handle redirecting https://defaultwebsite/lavarel to https://defaultwebsite/laravel/public like this:

<system.webServer>
    <rewrite>
        <rules>
            <rule name="Imported Rule 1-1" stopProcessing="true">
                <match url="^" ignoreCase="false" />
                <conditions logicalGrouping="MatchAll">
                    <add input="{HTTP_AUTHORIZATION}" ignoreCase="false" />
                    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
                    <add input="{URL}" pattern="(.+)/$" ignoreCase="false" />
                </conditions>
                <action type="Redirect" url="{C:1}" redirectType="Permanent" />
            </rule>
            <rule name="Imported Rule 2-1" stopProcessing="true">
                <match url="^" ignoreCase="false" />
                <conditions logicalGrouping="MatchAll">
                    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
                    <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
                </conditions>
                <action type="Rewrite" url="index.php" />
            </rule>
        </rules>
    </rewrite>
</system.webServer>

UPDATE I recently added this rule to root (default web site), but it doesn't seem to hit this rule when the laravel site requests resources. Even though I can see the HTTP_REFERER pattern is correct.

    <rewrite>
        <rewriteMaps>
            <rewriteMap name="Root" />
        </rewriteMaps>
        <rules>
            <rule name="Rewrite Root => Laravel" stopProcessing="true">
                <match url="(img|js|css)?(.*)" />
                <conditions>
                    <add input="{HTTP_REFERER}" pattern="^https://www.defaultsite.be/laravel(.*)" />
                </conditions>
                <action type="Rewrite" url="laravel/public/{R:1}{R:2}" appendQueryString="true" logRewrittenUrl="true" />
            </rule>
        </rules>
    </rewrite>
Score:0
ph flag

Well, I don't fully understand it myself. IIS will never be my friend :)

It started working when I change the rule to redirect instead of rewrite:

<rules>
    <rule name="Rewrite Root => Laravel" stopProcessing="true">
        <match url="(img|js|css)?(.*)" />
        <conditions>
            <add input="{HTTP_REFERER}" pattern="laravel/.*" />
            <!-- <add input="laravel\public\{R:1}{R:2}" matchType="IsFile" /> -->
            
        </conditions>
        <action type="Redirect" url="/laravel/{R:0}" appendQueryString="true" logRewrittenUrl="false" redirectType="Permanent" />
    </rule>
</rules>
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.