ASP.NET URL rewrites

Categories Web HostingScriptingASP.NET

Our Cloud Hosting Windows servers do not have an inbuilt URL rewrite module installed. A 3rd party module such as UrlRewritingNet is required to rewrite URL's on our Windows environment. Follow the below instructions to perform URL rewrites on our Cloud Hosting Windows server environment.

  1. Download UrlRewritingNet.UrlRewriter.dll.
  2. Create a bin directory on your hosting account.
  3. Upload the UrlRewritingNet.UrlRewriter.dll file into the bin directory.
  4. Configure a web.config file to utilise the rewrite module.
  5. Upload the web.config file into the root directory of the virtualhost

Note that the <configSections> element within the web.config  file must be the first  element after the <configuration> element  for the function to work correctly.

Example web.config file using UrlRewritingNet to rewrite URL's.

<configuration>
    <configSections>
         <section name="urlrewritingnet" restartOnExternalChanges="true"  requirePermission="false" type="UrlRewritingNet.Configuration.UrlRewriteSection, UrlRewritingNet.UrlRewriter" />
    </configSections>

    <system.webServer>
    <httpErrors errorMode="Detailed" />
        <modules>
          <add name="UrlRewriteModule" type="UrlRewritingNet.Web.UrlRewriteModule, UrlRewritingNet.UrlRewriter"/>
            </modules>
    </system.webServer>

    <system.net>
        <defaultProxy>
            <proxy
            usesystemdefault = "false"
            proxyaddress="http://proxy.private.netregistry.net:3128"
            bypassonlocal="true"
            />
        </defaultProxy>
    </system.net>

     <urlrewritingnet rewriteOnlyVirtualUrls="true" contextItemsPrefix="QueryString" defaultPage="default.aspx"  xmlns="http://www.urlrewriting.net/schemas/config/2006/07">
     <rewrites>

      <add name="GetProductCategories"  virtualUrl="^~/Categories/(.*).html"  rewriteUrlParameter="IncludeQueryStringForRewrite"  destinationUrl="~/test.aspx"  ignoreCase="true" />
      <add name="GetProduct" virtualUrl="^~/Products/(.*).html"  rewriteUrlParameter="ExcludeFromClientQueryString"  destinationUrl="~/test.aspx"  ignoreCase="true" />
     </rewrites>
    </urlrewritingnet>

        </rewrites>
    </urlrewritingnet>
</configuration>

Example of a web.config using UrlRewritingNet to rewrite and redirect sub domain URL's into sub directories.

<configuration>
    <configSections>
         <section name="urlrewritingnet" restartOnExternalChanges="true"  requirePermission="false" type="UrlRewritingNet.Configuration.UrlRewriteSection, UrlRewritingNet.UrlRewriter" />
    </configSections>

    <system.webServer>
    <httpErrors errorMode="Detailed" />
        <modules>
          <add name="UrlRewriteModule" type="UrlRewritingNet.Web.UrlRewriteModule, UrlRewritingNet.UrlRewriter"/>
            </modules>
    </system.webServer>
    
    <system.net>
        <defaultProxy>
            <proxy
            usesystemdefault = "false"
            proxyaddress="http://proxy.private.netregistry.net:3128"
            bypassonlocal="true"
            />
        </defaultProxy>
    </system.net>
    
     <urlrewritingnet rewriteOnlyVirtualUrls="true" contextItemsPrefix="QueryString"  xmlns="http://www.urlrewriting.net/schemas/config/2006/07">
        <rewrites>
    
        <add name="RewriteOne" virtualUrl="^http\://(.*).domain.tld/(.*)" rewriteUrlParameter="ExcludeFromClientQueryString" destinationUrl="$1/$2" rewrite="Domain" ignoreCase="true" />

        </rewrites>
    </urlrewritingnet>
</configuration>

Rate this article
Get more leads