【问题标题】:Add trailing slash to subfolder URL将尾部斜杠添加到子文件夹 URL
【发布时间】:2016-12-17 16:41:16
【问题描述】:

我使用 ASP MVC 作为我的语言,并且我有一个包含多个子文件夹/应用程序的网站。

www.sample.com

www.sample.com/zh

www.sample.com/en

我只需要在 URL 的末尾添加一个斜杠。

www.sample.com/zh/

www.sample.com/en/

我对 IIS 重写参数感到困惑。有人可以帮帮我吗?

【问题讨论】:

  • 你在使用 Url helper 来生成 url 吗?
  • 嗨。是的,没有。我有时只在代码中使用基本的相对 url。

标签: asp.net asp.net-mvc iis routing trailing-slash


【解决方案1】:

作为参考,我对规则做了一些修改:

<rule name="Add trailing slash" stopProcessing="true">
                    <match url="^.*" />
                    <action type="Redirect" url="{C:0}/" appendQueryString="true" redirectType="Permanent" />
                    <conditions>
                        <add input="{PATH_INFO}" pattern="\/zh$" />
                    </conditions>
                </rule>

这样,当遇到/zh时,它只会重定向到/zh/,而不破坏现有的url。

希望这对某人有所帮助!

【讨论】:

    猜你喜欢
    • 2013-06-13
    • 1970-01-01
    • 1970-01-01
    • 2018-11-18
    • 2012-08-03
    • 2012-09-25
    • 2012-07-06
    • 2021-04-18
    • 2021-12-14
    相关资源
    最近更新 更多