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>