I'm trying to set up a Django/Angular application under IIS.
When I set a similar application under nginx, I pass all URLs starting with /api
(my backend) or /admin
(the Django admin interface) to Django. I also set two locations: /
and /static
- both are aliases to the folder with all the static resources.
I need to alias /static
, too, because Django's admin application references resources at /static/admin/...
I can't get IIS to work the same way. I'm using wfastcgi
to interface with Django, and a rewrite rule to map /static
back to /
. This is the relevant portion of my Web.config
:
<rewrite>
<rules>
<rule name="Static Perfix" stopProcessing="true" >
<match url="^static/(.+)" />
<action type="Rewrite" url="{R:1}" />
</rule>
</rules>
</rewrite>
<handlers>
<add name="Admin"
path="/admin"
verb="*"
modules="FastCgiModule"
scriptProcessor="..."
resourceType="Unspecified" />
</handlers>
This doesn't work. When I access /admin
the handler catches it and forwards the request to Django, as it should. Django return an html page with resources located at /static/admin/base.css
(for example).
When the browser tries to load such a resource the rewrite rule catches it, rewrites it to /admin/base.css
, and then the handler catches it and forwards it to Django, which doesn't know what /admin/base.css
is and returns a 404.
I tried making /static
a Virtual Directory pointing to the same physical directory as the root directory. This caused all sorts of conflicts because my root Web.config
was read twice, causing all sorts of duplicate key violations (for all the keys I have defined, more or less).
I would appreciate any help on getting out of this situation.