locked
URL Rewriting the root folder to a subfolder RRS feed

  • Question

  • User-1919411965 posted

    This should be a simple rule but it doesn't seem to be working as expected.  I'm trying to redirect requests from localhost/ to localhost/webapp/.  The pattern I'm using is ^$, with no conditions, and rewrite url of webapp/.  But it never matches and always gives me the default IIS7 page.

    What is going on?  Why isn't it matching?

    Friday, October 9, 2009 4:58 PM

Answers

  • User-1919411965 posted

    I'm actually using IIS7 Url Rewrite 1.1 but conceptually same thing..

    I ran across this tidbit on http://learn.iis.net/page.aspx/460/using-url-rewrite-module/

    "IIS DefaultDocument module may redirect to rewritten URL when URL rewrite module rewrites to a folder. For example, if substitution URL in rewrite rule is "/folder1/folder2" and these folders exist on file system and have default document configured, then DefaultDocument module will redirect web client to "/folder1/folder2/", thus exposing rewritten URL. To prevent this from happening, use "/" at the end of the substitution URL when rewriting to a folder, e.g. "/folder1/folder2/""

    Which gave me the idea to adjust the Rewrite Url, and discovered its strange behavior.  Indeed, if you rewrite to a folder with a default document without the trailing slash it (erroneously?) exposes the rewritten url (as stated above).  Adding the trailing slash worked but oddly it then broke asp.net themes.  Finally adding the folder/default.aspx (or whatever your default document is) works as you would expect.

    Also I did have to remove the condition that it not match on a directory.  Here is the final rule fyi.

    <rule name="root" stopProcessing="true">
       <match url="^$" />
       <conditions>
          <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
       </conditions>
       <action type="Rewrite" url="WEBAPP/default.aspx" />
    </rule>


    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, October 10, 2009 9:44 PM

All replies

  • User1396024914 posted

    hi snives

    if you are using Intelligencia.UrlRewriter.dll for URL rewritting then make rewrite rule something like this :

    <rewriter>
          <rewrite url="~/Store/(.*)" to="~/yourfoldername/subfolder/yourPagename?Parameter"/>

           for ex

           <rewrite url="~/Store/(.*)" to="~/Admin/Adminsub/DynamicPage.aspx?name=$1"/>

    </rewriter>


    Please don't Forget to mark it as answer.


    Saturday, October 10, 2009 2:19 AM
  • User-1919411965 posted

    I'm actually using IIS7 Url Rewrite 1.1 but conceptually same thing..

    I ran across this tidbit on http://learn.iis.net/page.aspx/460/using-url-rewrite-module/

    "IIS DefaultDocument module may redirect to rewritten URL when URL rewrite module rewrites to a folder. For example, if substitution URL in rewrite rule is "/folder1/folder2" and these folders exist on file system and have default document configured, then DefaultDocument module will redirect web client to "/folder1/folder2/", thus exposing rewritten URL. To prevent this from happening, use "/" at the end of the substitution URL when rewriting to a folder, e.g. "/folder1/folder2/""

    Which gave me the idea to adjust the Rewrite Url, and discovered its strange behavior.  Indeed, if you rewrite to a folder with a default document without the trailing slash it (erroneously?) exposes the rewritten url (as stated above).  Adding the trailing slash worked but oddly it then broke asp.net themes.  Finally adding the folder/default.aspx (or whatever your default document is) works as you would expect.

    Also I did have to remove the condition that it not match on a directory.  Here is the final rule fyi.

    <rule name="root" stopProcessing="true">
       <match url="^$" />
       <conditions>
          <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
       </conditions>
       <action type="Rewrite" url="WEBAPP/default.aspx" />
    </rule>


    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, October 10, 2009 9:44 PM