简体   繁体   English

重写如何在web.config system.webserver中工作

[英]How does the rewrite works in web.config system.webserver

I have an asp.net mvc 4 application and i have this rule in web.config 我有一个asp.net mvc 4应用程序,我在web.config中有此规则

<system.webServer>
  <rewrite>
    <rules>
      <rule name="Remove Virtual Directory">
      <match url=".*" />
      <action type="Rewrite" url="{R:0}" />
    </rule>
  </rules>
</rewrite>

I can't understand why and how this works. 我不明白为什么以及如何运作。 I use it because godaddy adds a virtual path in the url with the name of the folder the application is in. ie example.com/foldername/index becomes example.com/index 我使用它是因为Godaddy在URL中添加了虚拟路径,并带有应用程序所在文件夹的名称。即example.com/foldername/index变为example.com/index

So how does it finds the virual path by ".*" and removes it. 那么它如何通过“。*”找到虚拟路径并删除它。 And what {R:0} is? {R:0}是什么? Thank you. 谢谢。

Well It seems that I the match url this regex matches every url and it doesn't allow to redirect a url that includes the virtual path. 好吧,看来我这个正则表达式的匹配URL匹配每个URL,并且不允许重定向包含虚拟路径的URL。 Since the routing of mvc finds the resource. 由于mvc的路由会找到资源。

As for {R:0}. 至于{R:0}。 The request url is the first argument hence the 0, and the regex is a secont argument not uses. 请求url是第一个参数,因此为0,而regex是未使用的secont参数。 This would be the {R:1}. 这就是{R:1}。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何以编程方式更改web.config中的system.webServer / defaultDocument - How to change system.webServer/defaultDocument in web.config programmatically web.config system.webServer与system.web - web.config system.webServer Vs system.web 需要有关system.webServer重写规则的正则表达式设计的帮助。 - Need help for regex design in system.webServer rewrite rule in web.config 如何从web.config system.web和system.webServer读取Ihttpmodule - how to Read Ihttpmodule from web.config system.web and system.webServer 用于访问system.webServer的基本IIS 7 web.config在哪里,以及如何通过代码对其进行编辑 - Where is the base IIS 7 web.config for accessing system.webServer and how do you edit it through code 如果指定路径上存在文件,则会忽略web.Config中system.webServer中的处理程序 - Handler in system.webServer in web.Config is ignored if a file exist at the path specified web.config iis7.0集成system.webserver处理程序和模块 - web.config iis7.0 integrated system.webserver handlers and modules web.config 继承:<clear/> 导致 XML 解析错误<system.webServer><modules> - web.config inheritance: <clear/> causes XML Parsing Error in <system.webServer><modules> 我的IIS 7 web.config中的system.webServer / security / authorization无法正常工作 - The system.webServer/security/authorization in my IIS 7 web.config is not working system.webserver中的设置有时会从web.config文件中删除 - Settings from system.webserver sometimes removed from web.config file
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM