【发布时间】:2018-02-19 07:14:26
【问题描述】:
我有一个托管在共享 Microsoft-IIS/8.5 服务器上的网页。 我没有该服务器的管理员权限,也无权访问它的配置文件,所以我无法确定URL rewrite 模块或HTTP redirect 元素是否正确安装/设置.
我想建立一个从名为 old_folder 的文件夹到名为 new_folder 的文件夹的重定向(对我来说都是根目录,即 http://sharedhosting.com/myusername/)。
我在根文件夹下放了以下web.config文件:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<configSections>
<sectionGroup name="system.webServer">
<sectionGroup name="rewrite">
<section name="rules" overrideModeDefault="Allow" />
</sectionGroup>
</sectionGroup>
</configSections>
<system.webServer>
<rewrite>
<rules>
<rule name="attempt" stopProcessing="true" enabled="true">
<match url="^old_folder/$" />
<action type="Redirect" url="new_folder/" redirectType="Permanent"/>
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
但我能得到的只是403 - Forbidden: Access is denied.(如果我留下一个空的old_folder)或404 - File or directory not found.(如果我删除它)。
我尝试使用HTTP Redirect,通过在old_folder 中放置一个包含Web.config 的文件
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<httpRedirect enabled="true" destination="http://sharedhosting.com/myusername/new_folder/" />
</system.webServer>
</configuration>
但这也没有用。
我知道我的 Web.config 文件已被读取(如果其中有错误,我会收到 500 个错误)。我怀疑安装了 URL 重写,因为例如,如果存在 folder 文件夹,http://sharedhosting.com/myusername/folder 将被重写为 http://sharedhosting.com/myusername/folder/(即带有斜线)。
我的规则正确吗?我的主机是否阻止我重定向?如果是,我怎么知道?
我在<rules> 标记后添加了<clear /> 以丢弃所有其他重写规则,但它仍然没有重定向任何内容。
我错过了什么?
赏金到期前的最后编辑 为了澄清,我的问题是“如何理解为什么服务器没有正确解释/忽略我的指令?”。
We came to the conclusion 可能是我的服务器设置得很奇怪,我正试图对其进行“还原工程”并检测是什么让服务器忽略了重定向/重写规则。
【问题讨论】:
标签: asp.net redirect iis web-config url-rewrite-module