IIS của chúng tôi lưu trữ trang web của riêng chúng tôi. Nhưng gần đây chúng tôi được giao nhiệm vụ lưu trữ một trang web của bên thứ ba được xây dựng bằng Laravel trong một thư mục con.
Trang web đang tải, nhưng hầu hết các tài nguyên như tệp CSS và JS không được tải (404) do cách trang web của bên thứ ba yêu cầu tài nguyên của trang web đó. Ví dụ:
<script source="/js/site.js"></script>
/js/site.js
Dịch sang https://defaultwebsite/js/site.js
mà không tồn tại.
tôi cần /js/site.js
để dịch sang https://defaultwebsite/laravel/public/js/site.js
.
Điều này có thể thực hiện được trong IIS 10 không?
Đây là một bản phác thảo của cây thư mục:
+ trang web mặc định
| + ấu trùng
| | + công cộng
| | | + js
| | | | - trang web.js
| | | - chỉ mục.php
| + js
| | - ourownjs.js
| - chỉ mục.php
Chúng tôi có hai quy tắc viết lại được thiết lập để xử lý chuyển hướng https://defaultwebsite/lavarel
đến https://defaultwebsite/laravel/public
như thế này:
<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>
CẬP NHẬT
Gần đây tôi đã thêm quy tắc này vào root (trang web mặc định), nhưng có vẻ như nó không đạt được quy tắc này khi trang laravel yêu cầu tài nguyên. Mặc dù tôi có thể thấy mẫu HTTP_REFERER là chính xác.
<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>