简体   繁体   English

使用重写添加“伪”根文件夹

[英]Adding a “fake” root folder using rewrite

I'm not sure where to go on this one. 我不确定该进行哪一步。 I've got rewrites to remove file extensions and such but what I can't seem to find out how to do is to add a "fake" root directory to the site. 我已经进行了重写,以删除文件扩展名,但我似乎无法找出如何做的就是向站点添加“伪”根目录。 For example if the site is www.foo.com/index.htm I'd like to rewrite the URL to show www.foo.com/root/index.htm. 例如,如果站点是www.foo.com/index.htm,我想重写URL以显示www.foo.com/root/index.htm。 I can use either the IIS rewrite module or mod rewrite I'm just uncertain on how to go about this (or if it's even possible) and my google-fu has failed me. 我可以使用IIS重写模块或mod重写,但我不确定如何执行此操作(或者甚至可能),但我的google-fu失败了。

If I understand it correctly, you want requests to come with root prefix. 如果我理解正确,则您希望请求带有root前缀。 In that case this rewrite will do it: 在这种情况下,此重写将执行此操作:

<rule name="StripRoot" stopProcessing="true">
    <match url="root/(.*)" />
    <action type="Rewrite" url="/{R:1}" />
</rule>

To modify the html served to the client outbound rule is required: 要修改投放到客户端出站规则的html,需要执行以下操作:

<outboundRules>
    <rule name="FakeRoot" preCondition="IsHtml">
        <match filterByTags="A, Area, Base, Form, Frame, IFrame, Img, Input, Link, Script" pattern="http://www\.foo\.com/(.*)" />
        <action type="Rewrite" value="http://www.foo.com/root/{R:1}" />
    </rule>
    <preConditions>
        <preCondition name="IsHtml">
            <add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
        </preCondition>
    </preConditions>
</outboundRules>

It assumes that you have fully qualified URL in tag attributes, if relative links are used you need more sophisticated rewrites. 它假定您在标记属性中具有完全限定的URL,如果使用相对链接,则需要更复杂的重写。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM