0

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. 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.

Hirthas
  • 359
  • 2
  • 13

1 Answers1

1

If I understand it correctly, you want requests to come with root prefix. 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:

<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.

Tomek
  • 3,267
  • 2
  • 22
  • 23
  • I put this in and it does not add the root/ directory to the url. However, when I type root/ into the url I don't get a 404 error like I would expect seeing as how that directory does not exist. Thank you very much for the suggestion. – Hirthas Dec 20 '12 at 13:30
  • It is difficult to figure out from your question what is the exact requirement. – Tomek Dec 20 '12 at 14:07
  • my website URL is www.foo.com/index.htm I want to rewrite it to become www.foo.com/root/index.htm because actually moving files is not an option. – Hirthas Dec 20 '12 at 18:00
  • also links aren't much of an issue because the links mostly go to one file that loads different files into itself – Hirthas Dec 20 '12 at 18:05
  • Ok, so I'm lost no idea what's the problem now :) – Tomek Dec 20 '12 at 21:37
  • I want to add a root/ directory too all the urls on my site. I put the code in but it does not add the root/ directory. the first rule is called StripRoot is it trying to take the root/ directory off? – Hirthas Dec 21 '12 at 19:41
  • when I type in www.foo.com/root/index.jsp the rules remove it just fine however the rewrite rule for some reason does not display the new www.foo.com/root/index.jsp in the url – Hirthas Jan 08 '13 at 15:14