Iis URL重写子虚拟目录

Iis URL重写子虚拟目录,iis,url-rewriting,Iis,Url Rewriting,假设我有这个网站: http://localhost/site/admin 其中site是IIS虚拟目录,admin是站点虚拟目录中的IIS虚拟目录。可以说,站点和管理员都是独立的网站,因为一个是主网站,另一个是管理员门户。我遇到的问题是URL的管理门户部分 假设我有一个index.php,它采用要显示的页面名称,例如: http://localhost/site/admin/index.php?p=cats 我使用URL重写允许上面的URL按如下方式编写: http://localhost

假设我有这个网站:

http://localhost/site/admin
其中site是IIS虚拟目录,admin是站点虚拟目录中的IIS虚拟目录。可以说,站点和管理员都是独立的网站,因为一个是主网站,另一个是管理员门户。我遇到的问题是URL的管理门户部分

假设我有一个index.php,它采用要显示的页面名称,例如:

http://localhost/site/admin/index.php?p=cats
我使用URL重写允许上面的URL按如下方式编写:

http://localhost/site/admin/cats
我刚刚使用IIS规则向导创建了此类规则:

模式:^[^/]+/$ 操作:index.php?p={R:1}

这个很好用

但是,我现在尝试访问如下URL:

http://localhost/site/admin/cats/123
^([^/]+)/([0-9]+)/?$
这实际上是:

http://localhost/site/admin/index.php?p=cats&id=123
我试图使用这样的模式:

http://localhost/site/admin/cats/123
^([^/]+)/([0-9]+)/?$
看起来URL工作正常,但副作用是我的所有相对路径现在都不正确。我想要的是:

http://localhost/site/admin/pages/header.php
但结果是:

http://localhost/site/admin/cats/pages/header.php
我认为这是因为被重写后的URL在管理部分后面有猫,但我不知道如何使其正常工作


谢谢

您至少应该做的是确保不重写现有页面/内容,例如header.php。此外,您还应该对从URL获得的部分进行URL编码。如果不进行彻底测试,这可能会起作用:

<rule name="Rewrite">
    <match url="^(([^/]+)/)+([\w]+)/?([0-9]+)?$"/>
        <conditions>
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/>
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true"/>
        </conditions>
    <action type="Rewrite" url="index.php?p={UrlEncode:{R:3}}&id={UrlEncode:{R:4}}"/>
</rule>