首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将IIS7上子文件夹的url regexp与web.config匹配

将IIS7上子文件夹的url regexp与web.config匹配
EN

Stack Overflow用户
提问于 2012-11-15 19:09:40
回答 1查看 1.7K关注 0票数 1

我正在使用获取简单的cms在我的国际空间站服务器(实际上必须使用国际空间站),并有一个插件,以启用重写国际空间站与web.config

web.config来源:

代码语言:javascript
复制
<?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>

但是我在主文件夹/和子文件夹/en上的内容管理系统,例如:

http://domainname.com/ (main cms) http://domainname.com/en/ (子文件夹中的另一个cms )

使用上面的web.config,主cms工作成功,但子文件夹上的cms不工作(与以前一样给出404 )

如何将子文件夹规则实施到web.config file?所以2个cms成功地工作了。

我试图将相同的web.config文件放在子文件夹(/en)下,但不起作用。

非常感谢,

EN

回答 1

Stack Overflow用户

发布于 2012-11-16 20:14:43

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

要使其也适用于/en,请将规则更改为:

代码语言:javascript
复制
<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>

如果您想要一个适用于任何两个字符的语言代码的更通用的解决方案,请使用以下代码:

代码语言:javascript
复制
<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中。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13396309

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档