Help rewriting base URL folders RRS feed

  • Question

  • User-2015964989 posted

    I've been scouring the net for an answer to this, and haven't found an answer yet. This should, I would think, be fairly simple.

    I have a website running on IIS7 at www.somesite.net. I want to set up URL rewriting so that I can have www.somesite.net/object1 map to www.somesite.net/objectviewer.aspx?i=object1

    All of the references I have found online refer to rewriting URL's another level down, such as www.somesite.net/object/object1, where the /object/ folder can be used to establish a regex match, but I need to actually accomplish this at the root level.

    As an added twist, this obviously should NOT try to remap certain objects that actually exist in the root, such as objectviewer.aspx itself, or the /images/ or /css/ folders.

    Has anyone done this? I thought it would be fairly straightforward, and I CAN get URL rewriting to work fine if I go another level down, but I invariably just end up with 404's if I try to apply it at the root. 

    Friday, November 20, 2009 1:49 PM


  • User-2015964989 posted

    Never mind, I worked it out myself. I ended up needing a redirect and a rewrite, and I got to learn all about conditions...which I didn't even know existed. Just in case anyone else ever asks:


              <rule name="redirectURL" stopProcessing="true">
                <match url="^objectviewer\.aspx$" />
                  <add input="{REQUEST_METHOD}" negate="true" pattern="^POST$" />
                  <add input="{QUERY_STRING}" pattern="^i=([^=&]+)$" />
                <action type="Redirect" url="{C:1}" appendQueryString="false" redirectType="Permanent" />
              <rule name="rewriteURL" stopProcessing="true">
                <match url="^([^/]+)/?$" />
                  <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                  <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                <action type="Rewrite" url="objectviewer.aspx?i={R:1}" />


    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, November 20, 2009 8:28 PM