从IIS中的嵌套应用程序的虚拟根目录下删除斜线 [英] Removing the trailing slash from a nested application's virtual directory root in IIS

查看:153
本文介绍了从IIS中的嵌套应用程序的虚拟根目录下删除斜线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个嵌套应用程序的网站。说虚拟目录是嵌套应用程序/应用程序。当一个请求到www.mysite.com/app做,重定向做成www.mysite.com/app/~~V,可能是因为虚拟目录不是空的。我有一个规则,嵌套应用程序的web.config从所有URL删除尾随斜线成立,但这并不影响嵌套应用程序的根路径。有没有一种方法(在IIS也许设置)重写或重定向到根没有结尾的斜线?我已经尝试了许多重写和重定向规则都无济于事。

I have a website with a nested application. Say the virtual directory is '/app' for the nested application. When a request is made to www.mysite.com/app, a redirect is made to www.mysite.com/app/, probably because the virtual directory is not empty. I have a rule set up in the nested app's web.config to remove trailing slashes from all urls, but this does not affect the root path of the nested application. Is there a way (maybe a setting in IIS) to rewrite or redirect to the root without the trailing slash? I have tried many rewrite and redirect rules to no avail.

下面是我的去除拖尾规则斜线:

Here is my rule for removing trailing slashes:

<rule name="Remove trailing slash" stopProcessing="true">
  <match url="(.*)/$" />
  <conditions>
    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
    <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
  </conditions>
  <action type="Redirect" redirectType="Permanent" url="{R:1}" />
</rule>

就像我说的,这个伟大的工程,但这并不影响根系。有一个在根Default.aspx页面,我想从www.mysite.com/app加载,而不是www.mysite.com/app~~V /.

Like I said, this works great, but this does NOT affect the root. There is a default.aspx page in the root that I want to load from www.mysite.com/app, NOT www.mysite.com/app/.

有一个变通的这?

推荐答案

我可能终于有了一个答案。这是Windows Server 2008 R2中,IIS 7.5。

I may finally have an answer. This is on Windows Server 2008 R2, IIS 7.5.

解决方案,在IIS:


  • 禁用子应用程序的默认文档功能。

  • 使用URL重写,创建规则重写(不定向)的空请求的Default.aspx

下面是web.config中的规则,并禁用默认文档的条目。我用UI做这些,而这也正是它创造:

Here is the rule in web.config, and the entry disabling the default document. I used the UI to do these, and this is what it created:

<defaultDocument enabled="false" />
<rewrite>
    <rules>
        <rule name="No slash root" enabled="true" stopProcessing="true">
            <match url="^$" />
            <action type="Rewrite" url="default.aspx" />
        </rule>
    </rules>
</rewrite>

这个问题似乎从有一个默认文档干。当我禁用默认文档,它从重定向,向一个403禁止,这是通常的目录浏览尝试改变。
然后添加规则重写空白请求跑的默认页面,而无需更改浏览器的URL。

The problem seems to stem from having a default document. When I disabled the default document, it changed from redirecting, to a 403 forbidden, which is the usual directory browsing attempt. Then adding a rule to rewrite the blank request ran the default page, without changing the browser url.

我只是禁用默认文档完全。也许可能只是删除默认文档列表中的Default.aspx,但我没有尝试。

I just disabled the Default Document entirely. Possibly could just remove the default.aspx from the default document list, but I didn't try that.

空请求规则是捡了没有别的www.mysite.com/app,并执行Default.aspx页。

The empty request rule is picking up the www.mysite.com/app with nothing else, and it executes the default.aspx page.

我做了一些测试,以确保页面仍然在子应用程序执行。我只是想确保它没有被神奇地以为这是根应用程序的文件。我通过创建各种.a​​spx文件读写良好的旧应用[ABC]变量这样做。儿童应用程序默认的文件可以读取由子应用的另一个文件写的变量。根级的文件并没有看到变量。

I did some tests to make sure the page was still executing in the child application. I just wanted to make sure it wasn't somehow magically thinking this was a file in the root application. I did this by creating various .aspx files to write and read good old Application["abc"] variables. The child app default file could read the variable written by another file in the child app. A root-level file did not see the variable.

有关更多的规则,我用赫利猿。我几年前开始与他们的软件,和我preFER在IIS语法htaccess的语法。我该使用上述规则在IIS中,以避免最后的斜线,以及APE / htaccess的为我所有保留的规则,这似乎是工作的考验。

For further rules, I use Helicon Ape. I started with their software years ago, and I prefer the htaccess syntax over the IIS syntax. I tested this using the rule above in IIS to avoid the trailing slash, and Ape/htaccess for all my remaining rules, and this seems to be working.

我做了很多的尝试获得单独猿避免重定向,但没有成功。看来IIS先走,所以这个规则需要在IIS,但其余的规则没有。

I made many attempts to get Ape alone to avoid the redirect, to no avail. It seems IIS goes first, so this rule needs to be in IIS, but remaining rules do not.

请注意:当试图这些规则,你的浏览器往往会缓存重定向。在隐身模式(浏览器)工作,和/或每次清除浏览器缓存。请参见 http://stackoverflow.com/a/9204355/292060

Note: When trying these rules, your browser tends to cache the redirects. Work in "incognito mode" (Chrome), and/or clear the browser cache every time. See http://stackoverflow.com/a/9204355/292060

这篇关于从IIS中的嵌套应用程序的虚拟根目录下删除斜线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆