2011-11-09 73 views
1

我想重写网址:IIS URL重写基于URL根

www.mydomain.com/urlfolder/filename.aspx

指向

www.mydomain.com /urlfolder/newfile.aspx

我的web配置有以下几点:

<rule name="PageRedirection" enabled="true" stopProcessing="true"> 
     <match url="urlfolder/filename.aspx" /> 
     <action type="Redirect" url="urlfolder/newfile.aspx" redirectType="Permanent" /> 
    </rule> 

的问题是,这正赶上网址,如:

www.mydomain.com/subdirectory/urlfolder/filename.aspx

我试图改变我的网址是 但^没有工作。它也似乎〜/没有工作来指定根。

我该如何去指定从根目录下的这个URL,而不是放入一个绝对路径。

我也有:

testsite.mydomain.com/

,我想部署在那里同样的web.config工作。 谢谢!

回答

2

我知道这个问题已经接近4岁了,所以你可能早已从需要回答开始。

^应该工作,虽然:

<rule name="PageRedirection" enabled="true" stopProcessing="true"> 
    <match url="^urlfolder/filename.aspx" /> 
    <action type="Redirect" url="urlfolder/newfile.aspx" redirectType="Permanent" /> 
</rule> 

^指定的路径字符串的开头,所以无论你^后把将在站点根和斜杠之后仅出现什么匹配。

例如

www.example.com/urlfolder/filename.aspx

会匹配。

www.example.com/subdirectory/urlfolder/filename.aspx

将不匹配。

我能想到的,为什么你说这会匹配/subdirectory/urlfolder/filename.aspx的唯一原因,是有你的web.config 在/子目录/副本在这种情况下www.example.com/subdirectory/被视为根。

如果是这种情况,并且将web.config复制到除根目录之外的其他位置,则另一个选项是将规则添加到%windir%\system32\inetsrv\config\ApplicationHost.config而不是web.config。这是包含适用于您计算机上所有IIS的所有设置的文件,而不仅仅是特定的站点。根据我的经验,Visual Studio会拒绝打开这个文件。但是,您可以在其他编辑器中编辑该文件,或通过IIS GUI设置重写规则。

在GUI中,在该文件树的顶层,此级别的可用工具包括URL Rewrite实用程序,以及在此设置的规则写入ApplicationHost.config。

希望这会有所帮助