【问题标题】:How to REWRITE a folder name in web.config with a different name?如何在 web.config 中用不同的名称重写文件夹名称?
【发布时间】:2019-08-22 20:52:06
【问题描述】:

我对 .htaccess 文件有所了解,但对 web.config 文件并不了解。这里有很多关于这个的问题,我不想问一个副本,但我无法让它工作。

这就是我想要做的。

我需要转换这个网址:

https://www.website.com/some-stuff-here/replacethis/some-more-stuff-here

到这个网址:

https://www.website.com/some-stuff-here/foobar/some-more-stuff-here

我需要将 replacethis 替换为 foobar

这是我尝试过的:

<rule name="Rewrite for Foobar">
    <match url="^replacethis/(.*)" />
    <action type="Rewrite" url="^foobar/{R:1}" />
</rule>

<rule name="Rewrite for Foobar">
    <match url="^/(.*)/replacethis/(.*)" />
    <action type="Rewrite" url="^/{R:1}/foobar/{R:2}" />
</rule>

我不知道我在做什么帮助我。 :(

【问题讨论】:

  • 为什么这个问题被标记为.htaccess
  • @arkascha 你是对的。已更新。

标签: iis web-config


【解决方案1】:

根据你的描述,我建议你可以尝试使用下面的url重写规则来达到你的要求。

注意:您应该将 localhost 网址替换为您的示例网址。

            <rule name="Rewrite for Foobar1">
              <match url="^replacethis/(.*)" />
              <action type="Rewrite" url="http://localhost:8082/foobar/{R:1}" />
            </rule>
            <rule name="foldername">
                <match url="(.*)/replacethis/(.*)" />
                <action type="Rewrite" url="http://localhost:8082/{R:1}/foobar/{R:2}" />
            </rule>

结果:

【讨论】:

    猜你喜欢
    • 2010-11-18
    • 1970-01-01
    • 1970-01-01
    • 2013-12-06
    • 2012-01-30
    • 2012-03-25
    • 1970-01-01
    • 2014-12-26
    • 1970-01-01
    相关资源
    最近更新 更多