Our Blog

A blog by InetSolution about programming, security, design and marketing for banks, credit unions and e-commerce.

How to Rewrite URLs in ASP on IIS Using ISAPI_Rewrite

Most search optimization experts know the benefits of including keywords in URLs. But many credit union and bank websites store content in a database and use query string values to pass a record identifier to a single page that displays the content dynamically. The URLs look like http://…/news-display.asp?articleid=7584. Unfortunately, this method does not allow you to show search engines your keywords in the page file name like you could with a static HTML page. There is a solution however, and it’s called URL rewriting.

Many optimization experts believe that search engines do look favorably upon pages that include keywords in the page name. Suppose you wanted to write an article titled “How to Use URL Rewriting to Improve Search Optimization.” If you were creating static HTML pages, in addition to the standard code and content optimization you’d perform, you could name your page something like, “how_to_use_URL_rewriting_to_improve_search_optimization.htm.” But how can you accomplish the same result if you’re using a database driven website?

If you’re using ASP.Net or Apache, you have numerous options since both applications have excellent support for URL rewriting. If, on the other hand, you’re using ASP, you may find that your options are not nearly as plentiful. You do have a couple of good options available though, including ISAPI_Rewrite and Ionic ISAPI Rewrite Filter for IIS. I’ll share an example of how I accomplished a fairly simple URL rewriting implementation for an ASP blog application using the ISAPI_Rewrite module for IIS.

My client had an ASP blog application that used a single page to display posts. The ASP page retrieved an article ID from a query string value. The URL looked like this http://..../view-blog.asp?articleid={BD721796-8B39-47B1-810A-5CF5DB63A954} Not only was it ugly to look at, but the URL did little to help their search optimization efforts. Instead of that mess, they wanted the pages to appear as static content to search robots and visitors, but did not want to restructure their entire website to support the change.

To begin, I created a regular expression in the ASP code to replace all spaces in the headline with underscore characters.


'We need to build our link name by replacing all spaces with an underscore
Set regEx = New RegExp
regEx.Global = true
regEx.IgnoreCase = True
regEx.Pattern = "\s"
strLink = Trim(regEx.Replace(strHeadline, "_"))


Next I wrote a second regular expression that would remove special characters from the article headline.


regEx.Pattern = "[^\w\.@-]"
strLink = Trim(regEx.Replace(strLink, ""))


Finally I saved this modified headline to a new database column that I called LINK. Prior to saving, I also perform a quick check to make sure that no articles exist with an identical headline.

With our SEO friendly headline ready, next I created a simple rewrite rule for ISAPI_Rewrite that looks like this:


RewriteRule /blog-(.*)\.htm /view-blog.asp\?articleid=$1 [I]

This rule checks for any page that begins with /blog- and ends with .htm and then rewrites the URL as view-blog.asp?articleid=MODIFIED_ARTICLE_HEADLINE. The $1 tells ISAPI_Rewrite to insert whatever value it found between /blog- and .htm. In our example, that would be

“how_to_use_URL_rewriting_to_improve_search_optimization”

and our full URL would look like

http://.../blog- how_to_use_URL_rewriting_to_improve_search_optimization.htm

To make this work, I also had to modify our query on the view-blog.asp page so that it queried the new LINK column rather than the GUID column. In addition, I modified the dynamic navigation code to use the value from the LINK column instead of the GUID article ID.

I did not have to change the structure of the site at all, nor did the client have to modify their content management process. The entire process took less than an hour and the only cost was the $60 for ISAPI_Rewrite. I have not tested the solution with the free IIRF for IIS, but it should work. 

Other Recent Blog Posts

Find this useful?

Want to receive our monthly tip to make your website easier to use and safer? No spam, just good advice. Signup!

Interests

Blog RSS Feed

Request a Consultation

Let us help you accomplish big goals.

Help us prevent spam: