You must Sign In to post a response.
  • Category: ASP.NET

    HOW TO URL REWRITING (Remove Only .aspx form Page URL)


    Are you searching about URL Re-writing in ASP.NET? Want to remove extension of file page? Read this thread to know more about URL Re-Writing in ASP.NET.



    Hi..friends,

    In My web application i just want to remove only .aspx from page url. I have searched on google and found many complicated solutions but i have need only an easy way just to remove only .aspx.

    For eg. My page url is : www.mydomain.com/careers.aspx

    should be look like this :www.mydomain.com/careers or www.mydomain.com/careers.html


    Please suggest me any link or code...

    Thanks
  • #735864
    You can make use of the URL Rewriter.net component for the same. Here is a sample code for the same.


    <configuration>
    <system.web>
    <urlrewrites>
    <rule>
    <url>/urlrewriter/show\.asp</url>
    <rewrite>show.aspx</rewrite>
    </rule>
    <rule>
    <url>/urlrewriter/wohs\.asp</url>
    <rewrite>show.aspx</rewrite>
    </rule>
    <rule>
    <url>/urlrewriter/show(.*)\.asp</url>
    <rewrite>show.aspx?$1</rewrite>
    </rule>
    <rule>
    <url>/urlrewriter/(.*)show\.html</url>
    <rewrite>show.aspx?id=$1&cat=2</rewrite>
    </rule>
    <rule>
    <url>/urlrewriter/s/h/o/w/(.*)\.html</url>
    <rewrite>/urlrewriter/show.aspx?id=$1</rewrite>
    </rule>
    </urlrewrites>
    </system.web>
    </configuration>




    <configuration>
    <configSections>
    <sectionGroup name="system.web">
    <section name="urlrewrites" type="ThunderMain.URLRewriter.Rewriter,
    ThunderMain.URLRewriter, Version=1.0.783.30976,
    Culture=neutral, PublicKeyToken=7a95f6f4820c8dc3"/>
    </sectionGroup>
    </configSections>
    </configuration>



    **************************

    <configuration>

    <configSections>
    <section name="rewriter"
    requirePermission="false"
    type="Intelligencia.UrlRewriter.Configuration.RewriterConfigurationSectionHandler, Intelligencia.UrlRewriter" />
    </configSections>

    <system.web>

    <httpModules>
    <add name="UrlRewriter" type="Intelligencia.UrlRewriter.RewriterHttpModule, Intelligencia.UrlRewriter"/>
    </httpModules>

    </system.web>

    <rewriter>
    <rewrite url="~/ " to="~ " /> (insert urls within quotes as mentioned above)
    </rewriter>

    </configuration>

    Thanks & Regards
    Anil Kumar Pandey
    Microsoft MVP, DNS MVM

  • #735872
    Hi Sunil,

    This depends on your Hosting environment and number of pages.
    If you have few pages and you know the URL of each possible cases, you can write them simply inside Web.config without requiring any additional change in code.

    <configuration>
    <system.web>
    <urlMappings enabled="true">
    <add url="~/About" mappedUrl="~/default.aspx?PageID=110"/>
    <add url="~/Contact" mappedUrl="~/default.aspx?PageID=120"/>
    <add url="~/Tutorials" mappedUrl="~/default.aspx?PageID=150"/>
    <add url="~/Tutorials/LongWord" mappedUrl="~/default.aspx?PageID=130"/>
    <add url="~/Tutorials/EnglishConversation" mappedUrl="~/default.aspx?PageID=140"/>
    </urlMappings>
    </system.web>
    </configuration>


    Or you can use Global.asax to re-write url for you. I have written a simple Article, read here
    http://www.dotnetspider.com/resources/44409-URL-Rewriting-ASP.NET-with-Global.asax.aspx

    All the Best.

    -------------
    Glad to be,
    John Bhatt
    Editor - DNS Forums
    https://www.pyarb.com

  • #735924
    Hi,

    Check these links,

    http://www.dotnetspider.com/forum/228735-URL-REWRITING-Very-Very-Urgent.aspx

    http://www.dotnetspider.com/forum/185489-URL-Rewriting.aspx

    http://www.dotnetspider.com/forum/172257-URl-Rewriting.aspx

    http://dotnetguts.blogspot.in/2008/07/url-rewriting-with-urlrewriternet.html

    http://blog.dotnettechy.com/2011/09/url-rewriting-in-aspnet-using.html

    http://forums.asp.net/t/1662327.aspx/1


  • Sign In to post your comments