[英]IIS URL Rewrite: Rewrite if file in specific path doesn't exist
I have a seemingly easy requirement of IIS' URL Rewrite module that I can't seem to get working for a Single Page Web App. 我对IIS的URL重写模块有一个看似简单的要求,但似乎无法为单页Web应用程序工作。 I have a root folder
content
and inside there is a folder dashboard
. 我有一个根文件夹
content
并且里面有一个文件夹dashboard
。 The URL uses dashboard
at the root (ie content
is omitted from the URL). URL在根目录使用
dashboard
(即,URL省略了content
)。 If a URL matches any file, I'd like it to serve that, otherwise, I'd like it to serve index.html
in the dashboard folder. 如果URL匹配任何文件,我希望它可以提供该文件,否则,我希望它可以提供显示板文件夹中的
index.html
。 The only complication is that dashboard is inside the content
folder in the filesystem but content
doesn't exist in the URL. 唯一的麻烦是,仪表板位于文件系统中的
content
文件夹内,但URL中不存在content
。
Here's my folder structure: 这是我的文件夹结构:
/content/dashboard/foo.txt
--> serve this for URL: /dashboard/foo.txt
/content/dashboard/foo.txt
>为网址提供此服务: /dashboard/foo.txt
/content/dashboard/assets/image.jpg
--> serve this for URL: /dashboard/assets/image.jpg
/content/dashboard/assets/image.jpg
>为网址提供此服务: /dashboard/assets/image.jpg
/content/dashboard/index.html
--> serve this for any URL that starts with /dashboard/
if there isn't a file that matches /content/dashboard/index.html
>如果没有与/dashboard/
匹配的文件,则将其提供给所有以/dashboard/
开头的URL
Here are my rewrite rules: 这是我的重写规则:
<rules>
<rule name="dashboard assets" stopProcessing="true">
<match url="^dashboard(.*)$" />
<conditions logicalGrouping="MatchAll">
<add input="content/{REQUEST_FILENAME}" matchType="IsFile" negate="false" />
</conditions>
<action type="Rewrite" url="content/dashboard{R:1}" />
</rule>
<rule name="dashboard app" stopProcessing="true">
<match url="^dashboard(.*)$" />
<action type="Rewrite" url="content/dashboard/index.html" />
</rule>
</rules>
Even though I have the dashboard assets
conditions above, it never seems to use it and always serves index.html. 即使我具有上面的
dashboard assets
条件,它似乎也从未使用过,并且始终提供index.html。 How can I correct this? 我该如何纠正?
{REQUEST_FILENAME} returns the full local directory path for the file requested. {REQUEST_FILENAME}返回所请求文件的完整本地目录路径。 eg /content/dashboard/assets/image.jpg variable {REQUEST_FILENAME} is actually C:\\inetpub\\wwwroot\\content\\dashboard\\assets\\image.jpg
例如/content/dashboard/assets/image.jpg变量{REQUEST_FILENAME}实际上是C:\\ inetpub \\ wwwroot \\ content \\ dashboard \\ assets \\ image.jpg
Remove the content/ from your condition input and it should work fine. 从条件输入中删除内容/,它应该可以正常工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.