We help IT Professionals succeed at work.

Removing .APSX from URL

Resna
Resna asked
on
Hi Guys,

I'm finding it difficult to find a specific tutorial onlie to remove .ASPX from my URLs using URL Rewrite in the web config file.  There seems to be more than one way to do it, and I'm not used to Windows server plus my client is putting pressure on me :(

The site is running on:
Windows Server 2008
IIS 7
ASP.NET with .NET framework v2.0  
ASP.NET with .NET framework v3.0 & 3.5


The URL's are:
http://tbglearning.com/About-Us.aspx


How I would like the URL's [remove the .ASPX]:
http://tbglearning.com/About-Us

Could some one help me write the re-write code please

Many thanks

Resna
Comment
Watch Question

You need URL rewriter
http://urlrewriter.net/

URL rewriter is open source best rewriter

Commented:
For few pages

you can use this

http://weblogs.asp.net/scottgu/archive/2007/02/26/tip-trick-url-rewriting-with-asp-net.aspx

If you have more number of pages or all the page you can go with AmanBhullar solution.

Author

Commented:
Thanks for the replies.

But the site is on a shared host.  And it seems you need to access to the IIS controls [which I don't have].

Any other ideas?

Many thanks

Resna

Commented:
Sample Download: A sample application that I've built that shows using this technique with the UrlRewriter.Net module can be downloaded here.  http://www.scottgu.com/blogposts/urlrewrite/UrlRewrite_HttpModule1.zip

What is nice about this sample and technique is that no server configuration changes are required in order to deploy an ASP.NET application using this approach.  It will also work fine in a medium trust shared hosting environment (just ftp/xcopy to the remote server and you are good to go - no installation required).
For http://urlrewriter.net/ you do not need access to IIS.
I am using the same in my site
for http://forum.littlekrazy.com/

Author

Commented:
Thanks for the replies

Just to clarify:
I know nothing about ASP(x), Windows server / IIS nor re writing URLs no a Windows / IIS server

Craig_F:
The file you linked is the same as the one I've downdloaded from the URL Re Write site.
How do I install it and what is the rule to remove .aspx from the end of all URL's.  You say FTP/upload it do you mean the whole directory in the same folder.

At the moment in the web config you sent this is the re write:
  <rewriter>
    <rewrite url="~/products/(.+).aspx" to="~/products.aspx?category=$1" />
  </rewriter>

Which is not relivant to the site I'm working on.

The reiterate:
1. I would like to know how to install Urlrewriter.
2. What should the rule be to remove .aspx from the URLs

AmanBhullar:
When visiting your forum I see normall URLs, like the below:
http://forum.littlekrazy.com/default.aspx?g=topics&f=2

Many thanks

Resna

on my forums, user is always on the default page.
You can use the url rewriter to remove .aspx.

Check the example for using tool
http://dotnetguts.blogspot.com/2008/07/url-rewriting-with-urlrewriternet.html
http://www.tutorialsasp.net/tutorials/url-rewriting-in-aspnet-using-urlrewriternet/

you can explore it more
Commented:
Another possible solution:

Create an empty solution in VS.NET, add a C# ASP.NET Web application (Call it "Cloaking"). Create and add 404.aspx, content1.aspx, content2.aspx and content3.aspx to your solution. Make sure to fill them up with some content so that you can distinguish them from each other.

In order to pull this trick off, you need to configure IIS to use the customized 404 error page (in this example, 404.aspx). To do that, go to the IIS administration console, select the correct website (in this example the website is called "Cloaking"). Right click it and choose "Properties" then select the "Custom Errors" tab.

Find the 404 entry in the list of errors and click "Edit properties". Select URL in the "Message Type" dropdown and type the full path to the 404.aspx page in the URL textbox, in this example "/Cloaking/404.aspx".

Switch back to VS.NET, open the Global.asax file and view the code. Scroll down to the Application_BeginRequest method and paste the following:

// The requested URL
string strURL = Request.RawUrl.ToLower();
   
// If the page didnt exist, the IIS tries to send the visitor to 404.aspx,
//this is where we intercept.
if(strURL.IndexOf("404.aspx") > 0) or if(strURL.IndexOf("404.aspx") < 0)
{
    // Scan the path for the keywords and rewrite the path to the preferred content
    if (strURL.IndexOf("products") > 0) Context.RewritePath("content1.aspx");
    if (strURL.IndexOf("sales") > 0) Context.RewritePath("content2.aspx");
    if (strURL.IndexOf("support") > 0) Context.RewritePath("content3.aspx");
}

Commented:
Oops, here is the code snippet
// The requested URL
string strURL = Request.RawUrl.ToLower(); 
    
// If the page didnt exist, the IIS tries to send the visitor to 404.aspx, 
//this is where we intercept.
if(strURL.IndexOf("404.aspx") > 0) or if(strURL.IndexOf("404.aspx") < 0)
{ 
    // Scan the path for the keywords and rewrite the path to the preferred content
    if (strURL.IndexOf("products") > 0) Context.RewritePath("content1.aspx");
    if (strURL.IndexOf("sales") > 0) Context.RewritePath("content2.aspx");
    if (strURL.IndexOf("support") > 0) Context.RewritePath("content3.aspx");
}

Open in new window

Author

Commented:
I'm not being funny, but no one seems to answering my questions, nor my original question.

1. I would like to know how to install Urlrewriter.
2. What should the rule be to remove .aspx from the URLs

Many thanks

Resna
There is no installer of urlrewriter.
You need to donload the DLL files.
Place them in Bin folder and start using it in project

Have you checked the links
http://dotnetguts.blogspot.com/2008/07/url-rewriting-with-urlrewriternet.html
http://www.tutorialsasp.net/tutorials/url-rewriting-in-aspnet-using-urlrewriternet/

First Link explains step by step way of configuring and using the urlrewriting