url - 如何在 IIS 中用斜杠重写 URL
问题描述
我目前有一个问题,我想从我的 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
- 索引.php
- 测试(默认登陆页面)
- 分测验
- 索引.html
- 索引.html
- 分测验
- phpmyadmin
当用户键入一个 URL 时,http://localhost/
他实际上应该重写为http://localhost/test
. 如果他打字http://localhost/subtest/
,那么他应该得到重写http://localhost/test/subtest
。
这已经适用于脚本。但问题是现在我无法输入http://localhost/subtest
(缺少尾部斜杠)并且也无法重写http://localhost/test/subtest
. 相反,我被重定向到http://localhost/test/subtest
,当然它不会找到该文件夹,因为根仍然保留在该test
文件夹中。
有人能帮我吗?
先感谢您。
解决方案
经过多次尝试,我现在找到了解决方法。现在我正在检查是否首先使用测试文件夹调用了 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>
推荐阅读
- php - 在 Wordpress 登录后将特定用户角色重定向到特定位置
- applescript - AppleScript 移动鼠标并单击 Photoshop 中的特定元素
- c - 将字符转换为整数是创建一个负数?
- delphi - TIdHTTPServer 缓慢使用所有连接
- python - 无法通过串行/Modbus 从 Windows 10 连接到 EPsolar Tracer 3210an 充电控制器
- r - R,如何将数据框的所有列名放入公式中?
- java - Java、Selenium 和 Method.invoke():获取 NoSuchMethodException
- python - Pandas 将列值匹配到同一数据框中的多个列
- r - 即使不存在也添加中断
- date - 如何在 Amazon Redshift 查询中选择上个季度/最近 2 个月的数据