// Articles. Tutorials. Utilities.
Home  |   Search  |   Login  
Categories Skip Navigation Links
New / All
Google / Android
Python / IronPython
SQL Server
Generate a Search Engine Friendly string instead of using ID
It's easy and convenient to obtain articles, blog posts, etc. via ID as query string. But the page generated with ID paramater has less of a chance of being indexed by search engine. Instead of ID, use a more search-engine-friendly name in the URL.
Table of Contents

In order to show an article or a news item or a blog post or any piece of information, you might be using a URL like the following:


You would have set up the ShowArticle.aspx page which parses out the query string and according to the ID parameter, you will go to the database and obtain the content and fill the fields on the aspx page. This works just fine; but the only problem is that the search engines don’t like this type of URLs.

Instead you want your url to be something like the following:


These names can be generated by using the titles of the news snippets or the blog posts themselves. Three things are done here:

  • convert the string to lower case (looks nicer)
  • take out all the non-alpha-numeric characters (both looks and need)
  • replace the the whitespace with dashes (-)

Following is the code:

/// <summary>
/// Generates a search-engine-friendly url
/// </summary>
/// <param name="title">Regular title</param>
/// <returns>Friendly Name</returns>
private string GenerateName(string title)
    // Convert the string into lower case
    title = title.ToLower();
    // Remove all the characters that are not alpha-numeric or spaces.
    title = Regex.Replace(title, @"[^\w\s]", "");
    // Replace whitespace characters (whitespace characters include spaces, tabs, etc.)
    // with dashes (-)
    title = Regex.Replace(title, @"\s+", "-");
    return (title);

Bookmark and Share This

More Articles With Similar Tags
The backspace escapes the special characters like period in the regular expressions. This article contains some examples of how to match and not match special characters like period.
This article contains information on various search robots and robots.txt. Thoughts on which directories to be allowed access and which are to be kept away from the search engines.
RewritePath used to service search engine friendly urls has problems with search engines. While this works fine with regular browsers, the request fails with the user agents of most all search engines. This article looks at the workarounds (fix from Microsoft was not available by early 2007)
You don't want to show ads from adsense while you are testing your site. This will inflate your adsense numbers and there is a chance of you accidentally clicking on one of the ads. Google does not allow you clicking on ads shown on your site. This article shows how to be safe and not show ads while testing.
With ID as a query string parameter (...aspx?ID=...) being a big no-no from the search engine perspective, we would need a way to convert the convenient fake urls into the ones our system understands (like using ID= in the url). There are several ways of accomplishing this; we will look at a couple of quick options.
About  Contact  Privacy Policy  Site Map