Click here to Skip to main content
15,891,529 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to rewrite url using urlrewrite to remove default.aspx from www.mydomain.com\default. Aspx
Posted

I really believe that the default.aspx is the default landing page in your application, if so, IIS would not bother asking for it even if you go to the URL without having the default.aspx concatenated to the URL at the end. So, you can try using the page without it.

You can use Visual C# for this,

C#
// get the URL
var url = Request.Url;
// get the page user's at
// General URL: "http://www.example.com/default.aspx"
// Get the string at the index 4 (3 if talking zero based)
var page = url.Split('/')[3];
// If the page is default.aspx
if(page == "default.aspx") {
   // Redirect him
   Response.Redirect("~/");
}


You can edit your web.config file and write this code in it, to prevent the default.aspx in your URL. Reference.

HTML
<rewrite>
    <rules>
        <rule name="san aspx">
          <!--Removes the .aspx extension for all pages.-->
          <match url="(.*)" />
          <conditions logicalgrouping="MatchAll">
            <add input="{REQUEST_FILENAME}" matchtype="IsFile" negate="true" />
            <add input="{REQUEST_FILENAME}" matchtype="IsDirectory" negate="true" />
          </conditions>
          <action type="Rewrite" url="{R:1}.aspx" />
        </rule>
    </rules>
</rewrite>


.. and trust me, there are many (and many) other methods that you can use to perform such tasks. Url Routing is one of them.
 
Share this answer
 
Comments
Sharon 2 15-Nov-14 11:03am    
If u r coming from other pages to home page default.aspx will be shown.
One more thing I want to redirect https:// www.mydomain.com to http:// www.mydomain.com only for homepage.
Afzaal Ahmad Zeeshan 15-Nov-14 11:05am    
That is because, you're adding the default.aspx in the hyperlink. Remove it.

HTTPS to HTTP conversion is a certificate related. Have you tried asking the admin (of your website) for help?
Sharon 2 25-Nov-14 0:59am    
Certificate issue is coming for redirect from https://domain.com to https://www.domain.com please help me..Any idea..
Afzaal Ahmad Zeeshan 25-Nov-14 3:24am    
Your hosting provider might not allow that www in the link, use domain.com only. :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900