2012-11-15 59 views
1

我使用在我的ISS服务器上获得简单的cms(实际上必须使用ISS)并且有一个插件可以在国际空间站上用web.config进行重写。匹配URL在IIS 7上的子文件夹regexp与web.config

的web.config来源:

<?xml version="1.0" encoding="UTF-8"?> 
<configuration> 
<system.webServer> 
    <rewrite> 
     <rules> 
      <rule name="GetSimple Fancy URLs" stopProcessing="true"> 
       <match url="^([^/]+)/?$" /> 
       <conditions> 
        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> 
        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> 
       </conditions> 
       <action type="Rewrite" url="?id={R:1}" /> 
      </rule> 
    </rules> 
    </rewrite> 
</system.webServer> 
</configuration> 

,但我的CMS两个主文件夹/和子文件夹/en如:

http://domainname.com/(主CMS) http://domainname.com/en/(另一个在子文件夹CMS)

与上述web.config,成功地工作,但主要CMS上的子文件夹CMS不工作(给404之前那样)

我如何可以实现子文件夹规则web.config file?所以2 cms成功地工作。

我试图把相同的web.config文件下的子文件夹(/en),但没有奏效。

非常感谢,

回答

0

首先,你的正则表达式将只匹配URL的是几乎在你的网站的根目录,例如domain.com/pagedomain.com/anotherpage。它不会匹配像domain.com/subdir/page这样的子目录。但那可能正是你想要的,我不知道。

,使其与/en工作,以及,改变规则:如果你想要一个更通用的解决方案,对于任何两个字符的语言代码工作

<rule name="GetSimple Fancy URLs" stopProcessing="true"> 
    <match url="^(en/)?([^/]+)/?$" /> 
    <conditions> 
     <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> 
     <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> 
    </conditions> 
    <action type="Rewrite" url="{R:1}?id={R:2}" /> 
</rule> 

,使用此:

<rule name="GetSimple Fancy URLs" stopProcessing="true"> 
    <match url="^([a-z]{2}/)?([^/]+)/?$" /> 
    <conditions> 
     <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> 
     <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> 
    </conditions> 
    <action type="Rewrite" url="{R:1}?id={R:2}" /> 
</rule> 

这应该只在您的根目录中的web.config