所以我一直在为我的Angular.js应用程序和IIS重写而苦苦挣扎。我有我的网站坐在http://server/jwb/文件夹。我将它重写为/ jwb /中的index.html文件,并且我在index.html中有一个。问题是,当我导航到http://server/jwb/parties/12345时,通过角度完成时看起来很好,但是当我在浏览器上进行刷新时,我失去了CSS和javascript。我看在控制台,他们正在被重写到http://server/jwb/parties/js/nameoffile.js等。我想要做的是告诉IIS重写总是看到他们真正居住在哪里的js,css和img文件,这是http://server/jwb/js,http://server/jwb/css和http://server/jwb/img等IIS Rewrite在刷新时失去Angular应用程序的路径
什么是重写规则,将为我做到这一点?有没有比使用重写规则更好的方法?
我现在有这个在我的web.config:
<rules>
<rule name="Imported Rule 1" stopProcessing="true">
<match url="^index\.html" ignoreCase="false" />
<action type="None" />
</rule>
<rule name="Imported Rule 2" stopProcessing="true">
<match url="." ignoreCase="false" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="index.html" />
</rule>
</rules>
然而,这仍然不奇怪的事情。我甚至做了一些测试,相对路径,这里是我的发现:
现在我们已经测试引用文件下列方式:
<link rel="stylesheet" href="css/bootstrap.css" />
OR
<link rel="stylesheet" href="/css/bootstrap.css" />
OR
<link rel="stylesheet" href="./css/bootstrap.css" />
或
<link rel="stylesheet" href="../css/bootstrap.css" />
而他们都没有工作。下面显示了当我们使用每个文件引用我们的应用程序的路径时会发生什么。为了便于讨论,我们的路径如下:
index --> http://10.34.34.46/jbvdev/calendar
documents --> http://10.34.34.46/jbvdev/documents/BC498484
caseNotes --> http://10.34.34.46/jbvdev/casenotes/CV/LA%20/2081/BC498484
尝试添加基本标记或在页面本身中使用资源的绝对路径 – charlietfl
''link rel =“stylesheet”href =“/ css/bootstrap.css”/>'实际上是一个绝对路径...寻找css目录在网站的根目录。最前面的'/'告诉浏览器以根目录开始,或者任何基本标签定义为root – charlietfl