How to SEO friendly an existing ASP .NET 3.5 web a

2019-05-29 18:08发布

问题:

So, I know there's a lot of this subject here and over the Internet. But most articles/questions refers to "static" url rewriting, like:

www.site.com/products.aspx?category=Books

So they rewrite it to

www.site.com/Products/Books

That's ok but I need something else.

The site is like a CMS, it has different types of content.

Nowadays to read the article titled "How StackOverflow helps you in your development" you need to go to an URL like the following.

www.site.com/viewContent.aspx?Id=1234

What I want to achive is:

www.site.com/Content/Articles/how-to-stackoverflow-helps-you-in-your-development

So as I understand, I need to involve ASP .NET in that, because first I need to retrieve the article (an its title of course) and then rewrite the URL.

But I'm wondering how the hell ASP .NET will know how to get that article if I go to that URL, it doesn't include the id anywhere... So maybe I could accept something like

www.site.com/Content/Articles/1234/how-to-stackoverflow-helps-you-in-your-development

I'm kind of lost here really.. I've never done any URL Rewriting at all and I've googled a lot and I cannot find a way to do what I want. Maybe what I want is not called url rewriting??? I don't know...

The site is running under Windows 2003 Server, IIS6, ASP .NET 3.5 SP1 And of course, I need a free solution, cannot spend 100usd on the ISAPI mod (besides I don't know if that is going to do what I need).

Thanks to all and sorry if this is a duplicated question, but I couldn't find it.

EDIT: I don't need to support non-ASP.NET files (jpgs, gifs, etc) don't need to be rewritten. I just need to rewrite the viewContent page to include the content title into the URL.

回答1:

You can use the new Routing that comes with ASP.Net 3.5 sp1 to have clean URLs.

This can even be done in web forms and not just MVC. ( I have done it myself). See here and here for exanples of how to set it up.

You can throw the Id of the article and the title in the URL and make the Id the real parameter that gets used to search for the article. That is what SO does. Try removing the question for the URL and it will take you to the same place.

Even if you don't use the Id you can pass the title of the article "how-to-stackoverflow-helps-you-in-your-development" to your DB and retreive the article based on the title.

With regards to IIS 6 it is a little trickier since IIS 6 by default can't handle extension-less URL's.

There are a few work arounds:

  1. Use the wildcard mapping in IIS to map all requests to Asp.Net
  2. Put Default.aspx at the end of your urls

See this post for other possible solutions.

Although the first solution may have performance issues if all content in your site goes through Asp.Net (even images, css, .html ...) in a small site it shouldn't matter. I have used this approach and there wasn't any major performance issues. I think it is the simplest solution. Here is the website I built with it

I hope this helps.



回答2:

This one is free, I have used it and it works pretty well: http://www.codeplex.com/IIRF

The nice thing is that it will handle url's without an extension (i.e. .aspx, .html, etc.)



回答3:

You can achieve this with ASP.NET routing.You can do this with ASP.NET MVC as well as Webforms.No need to do anything with IIS.

Check the below link

http://www.4guysfromrolla.com/articles/051309-1.aspx#postadlink

I did URL routing in my web application within 1 hour with the details from the above link.Its quite simple to learn .They provide sample codes too.It will help you to do it easily

You can retrieve the Id of the content using the title.But title should be unique.You can use ajax to check whether the title is a already existing one when user takes mouse out from the textbox.



回答4:

Easiest way is to add a http module to your current webforms project.

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

This shows you the basics of it, But it can easily be expanded so that the pages you want to rewite is taken from a database or even built on the fly.



回答5:

ASP.net MVC is your friend for that

stackoverflow use MVC