【问题标题】:How to rewrite URL with trailing slash in IIS如何在 IIS 中用斜杠重写 URL
【发布时间】:2018-12-11 08:21:14
【问题描述】:

我目前有一个问题,我想从我的 IIS web.config 文件的根文件夹中重写一个 URL。我的配置现在看起来像这样:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="phpmyadmin" stopProcessing="true">
                    <match url="(.*)phpmyadmin(.*)" />
                </rule>
                <rule name="redirect" stopProcessing="true">
                    <match url="(.*)" />
                    <action type="Rewrite" url="/test/{REQUEST_URI}" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

安装的也是 phpMyAdmin,你可以在配置中看到。它将被分开,因为我确实有以下文件结构:

  • wwwroot(根)
    • phpmyadmin
      • index.php
    • 测试(默认登陆页面)
      • 子测试
        • index.html
      • index.html

当用户输入像http://localhost/ 这样的URL 时,他实际上应该被重写为http://localhost/test。如果他输入http://localhost/subtest/,那么他应该重写http://localhost/test/subtest

这已经适用于脚本。但现在的问题是我无法输入http://localhost/subtest(缺少尾部斜杠)并且还可以重写http://localhost/test/subtest。相反,我被重定向到http://localhost/test/subtest,当然它不会找到该文件夹​​,因为根仍保留在test 文件夹中。

有人可以帮我吗?

提前谢谢你。

【问题讨论】:

    标签: url iis url-rewriting web-config


    【解决方案1】:

    经过多次尝试,我现在找到了解决方法。现在我正在检查是否首先使用测试文件夹调用了 URL。如果是这种情况,它将重定向到正确的 URL。

    <?xml version="1.0" encoding="UTF-8"?>
    <configuration>
        <system.webServer>
            <rewrite>
                <rules>
                    <rule name="phpmyadmin" stopProcessing="true">
                        <match url="(.*)phpmyadmin(.*)" />
                    </rule>
                    <rule name="redirect" stopProcessing="true">
                        <match url="^test/(.*)" />
                        <action type="Redirect" url="/{R:1}" />
                    </rule>
                    <rule name="rewrite" stopProcessing="true">
                        <match url="^(.*)" />
                        <action type="Rewrite" url="/test/{R:0}" />
                    </rule>
                </rules>
            </rewrite>
        </system.webServer>
    </configuration>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-04
      • 2022-08-19
      • 2016-03-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多