URL Rewrite - Hide SubDirectory name from the URL. [Answered]RSS

11 replies

Last post Jan 07, 2012 01:07 AM by dilipnikam

  • URL Rewrite - Hide SubDirectory name from the URL.

    Dec 14, 2011 04:28 AM|dilipnikam|LINK

    Hi,

     I wanted to hide the Sub Directory name from the URL. Is this possible in URL Rewriting....?

    Example as below.

    I have Root site as http://Site.com

    Which contains the Sub directory as MicroSite. This MicroSite Contains the Site1,Site2,Site3.

    When i am accessing the sites then URL look like  

    http://Site.com/Microsite/Site1/default.aspx

    http://Site.com/Microsite/Site2/default.aspx

    http://Site.com/Microsite/Site3/default.aspx

     

    Now i wanted to hide Microsite from the URL. Can you please guide me to achieve the output.

    URL Rewrite Sub Directory

  • Re: URL Rewrite - Hide SubDirectory name from the URL.

    Dec 14, 2011 11:23 AM|Uk-Sam|LINK

     Check this similar thread with solution

  • Re: URL Rewrite - Hide SubDirectory name from the URL.

    Dec 15, 2011 01:24 AM|dilipnikam|LINK

     Thanks Uk-Sam for Quick reply.

     I follow your link....But still its not work as required..... Still i digging it....If you got anything please let me know....

     Thanks in advance...

  • Re: URL Rewrite - Hide SubDirectory name from the URL.

    Dec 15, 2011 10:03 PM|Lloydz|LINK

    Hi,

    To hide the microsite directory in url, you can use the following rules:

    <rewrite>
      <rules>
        <rule name="HideMicroSite" stopProcessing="true">
          <match url="^microsite/(.*)" />
          <conditions>
            <add input="{HTTP_HOST}" pattern="^site\.com$" />
          </conditions>
          <action type="Redirect" url="{R:1}" />
        </rule>
        <rule name="RewriteToMicroSite">
          <match url="^(?!microsite)(.*)" />
          <conditions>
            <add input="{HTTP_HOST}" pattern="^site\.com$" />
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
          </conditions>
          <action type="Rewrite" url="microsite/{R:1}" />
        </rule>
      </rules>
    </rewrite>

    Let me know if this work for you, thanks.

  • Re: URL Rewrite - Hide SubDirectory name from the URL.

    Dec 16, 2011 09:20 AM|dilipnikam|LINK

     Thank you so much Lloydz.... :)

     Solution is working fine..... Need to check with Live server and let you know.

    Thanks again...

  • Re: URL Rewrite - Hide SubDirectory name from the URL.

    Jan 05, 2012 02:25 AM|dilipnikam|LINK

     Hi Lloydz....

    When accessing the site http://Site.com/Microsite/Site1/default.aspx its perfectly rewrite with the http://Site.com/Site1/default.aspx and page is visible & accessible.

     When i am accessing the root site with the URL as http://site.com/Pages/default.aspx then i have received the below error.

    The resource cannot be found.

    Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable.  Please review the following URL and make sure that it is spelled correctly.

    Requested URL: /
    microsite/Pages/default.aspx
     


     Please help me out to resolve the problem. Thanks in advance...

  • Re: URL Rewrite - Hide SubDirectory name from the URL.

    Jan 05, 2012 02:37 AM|Lloydz|LINK

    Hi,

    Could you please confirm whether the page exist in "/Page/default.aspx" or "/microsite/Pages/default.aspx"? Accoring to the error, it seems that the default page does not exist in the "Page" folder under site root, in this case, the rewrite rule works and rewrite it as "/microsite/Pages/default.aspx". And if the page doesn't exist at the rewrite path either, you will encounter this error. Ensure the default page exist under either ""/Page/" or "/microsite/Pages/" will prevent the error.

    If the issue persists, feel free to let me know.

    Thanks.

  • Re: URL Rewrite - Hide SubDirectory name from the URL.

    Jan 05, 2012 02:50 AM|dilipnikam|LINK

     Hi Lloydz

     Thanks for all the help & Prompt reply. I will try and explain my issue better below:

    I have a root site which is below url

    http://Site.com/pages/default.aspx

    and some microsites which are below url

    http://Site.com/Microsite/Site1/default.aspx

    http://Site.com/Microsite/Site2/default.aspx

    http://Site.com/Microsite/Site3/default.aspx

    When I embed the url rewrite tags in web.config, the microsites start work fine but the root site gives the error which i have mentioned in this post.

    I hope this clarifies my issue. Thanking you in advance.

     

  • Re: URL Rewrite - Hide SubDirectory name from the URL.

    Jan 05, 2012 03:03 AM|Lloydz|LINK

    Hi,

    Based on your description, the page should work correctly if the page do exist. Could you please follow the steps in the article below:

    Using Failed Request Tracing to Trace Rewrite Rules
    http://learn.iis.net/page.aspx/467/using-failed-request-tracing-to-trace-rewrite-rules

    reproduce the issue and then share the tracing logs. This will provide more information and help locate the root cause.

    Thanks.

  • Re: URL Rewrite - Hide SubDirectory name from the URL.

    Jan 05, 2012 04:39 AM|dilipnikam|LINK

     Hi,

    I have generated the Log file via Failed Request Tracing Rules. Below is the URL

    http://prosares.co.cc/Log.rar 

     Actually problem occurrences when the microsites world not found in the URL. If found then its work fine.

     For the example i have use word as microsites but in actual scenario its has uti-mf. 

    RequestURL="http://localhost:9010/Pages/default.aspx"

    after rewrite rules apply it become "http://localhost:9010/uti-mf/Pages/default.aspx"

     Web.config rewrite rule

    <rule name="HideMicroSite" stopProcessing="true">
              <match url="^uti-mf/(.*)" />
              <conditions>
                <add input="{HTTP_HOST}" pattern="^localhost:9010$" />
              </conditions>
              <action type="Redirect" url="{R:1}" />
            </rule>
            <rule name="RewriteToMicroSite">
              <match url="^(?!uti-mf)(.*)" />
              <conditions>
                <add input="{HTTP_HOST}" pattern="^localhost:9010$" />
                <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
              </conditions>
              <action type="Rewrite" url="uti-mf/{R:1}" />
            </rule>

     

  • Re: URL Rewrite - Hide SubDirectory name from the URL.

    Jan 05, 2012 08:44 PM|Lloydz|LINK

    Hi,

    I failed to download the logs via the link you provided, could you please sent it to me vai v-chaozh(at)microsoft(dot)com?

    As I said, the rule will rewrite to "uti-mf" path only when "/page/default.aspx" file does not exist. Please double check whether the file "page.aspx" exist at the path "<site root>/page/". If the file exists but the rewrite still happens, there must be other rules taking effect, and the tracing logs will show the details.

    Thanks.

     

  • Re: URL Rewrite - Hide SubDirectory name from the URL.

    Jan 07, 2012 01:07 AM|dilipnikam|LINK

     Yesterday i have mail you the Log files. Still if you not received please let me know. Will send it again.

     Thanks for your Quick support.