URL rewriting is usually used to make a URL for a dynamic web page more presentable, either for the reader or for search engines.
For example, a regular Classic ASP URL might look like this:
http://www.ford.com/page.asp?model=explorer&year=1999A more presentable way of rewriting the URL might be:
http://www.ford.com/explorer/1999/It used to be that search engines would not index pages with querystrings (the information after the .asp? in the URL). These days this is not the case and most search engines do index these types of pages. However, it has been suggested that major search engines might not be able to use more than three querystring parameters.
Also many search engines do look for keywords in the URL, but probably not in the querystring.
If you can remove the querystring altogether then you may stand a better chance with the search engines.
How to do URL rewriting in Classic ASP?
Unfortunately Classic ASP can't usually recognize URLs like this unless you happen to create static pages in each location.
For dynamic database-driven pages the simplest solution is to use an ISAPI filter but these cannot not always be installed, depending on your web host.
There are a couple of methods that can be used to do this in Classic ASP without installing additional components.
URL redirection in ASP using custom error pages
If you are able to set up custom error pages then you can create an error page that can translate these rewritten URLs and transfer to the correct page.
For a relatively simple to implement example of this:
Use the following script in your custom error page:
strQuery = Request.ServerVariables("QUERY_STRING")You need to modify it a little. Change all of the page.asp and page2.asp to your own page names and add more of these lines if necessary. And add a custom error message after the Else line so that normal errors are still display when needed.
strPage = Mid(strQuery, InStrRev(strQuery, "/") + 1)
' Change page.asp and page2.asp and add duplicate lines for
' each page you want redirection
If strPage = "page.asp" Then
ElseIf strPage = "page2.asp" Then
'Put your normal error page here
Add the following function to the beginning of each of your scripts that will use URL redirection:
Function RequestQS(strParam)Then in your scripts, instead of using the usual request/request.querystring/etc to retrieve your paramaters, use RequestQS(param-name).
strQuery = Request.ServerVariables("QUERY_STRING")
lngStart = InStr(strQuery,"/" & strParam & "/")
RequestQS = ""
If lngStart > 0 Then
lngStart = lngStart + Len("/" & strParam & "/")
lngEnd = InStr(lngStart + 0, strQuery, "/")
If lngEnd > 0 Then
RequestQS = Mid(strQuery, lngStart, lngEnd - lngStart)
When calling the page use the following format:
http://www.mydomain.com/param1name/param1value/param2name/param2value/page.aspYou can then request the values of param1name, param2name etc by using RequestQS. (NB. You can include as many parameters as you need.)
This example lacks any protection against characters that might cause problems in directory names. If the parameter had a / (forward slash) in it then it will cause problems. You are best to pass only text or numbers and perhaps a few other symbols like the minus sign. This may require additional functions to convert then reconvert unwanted characters.
A few negatives to using custom error pages have been suggested. One is that the error may be logged so if you are using this method your error logs may be huge. Another is that this may take up extra server processing time but I personally doubt there would be a significant difference.
URL redirection in ASP using subdomains
Another interesting possibility, for which I am not sure of the consequences to search engines, is using subdomains to store parameters. This eliminates the need to use custom error pages and puts keywords into the subdomain which may be treated as more important than directories by some search engines.
For example, using the sample example URL as above:
http://www.ford.com/page.asp?model=explorer&year=1999A more presentable way of rewriting the URL using subdomains might be:
http://explorer.1999.ford.com/page.aspThis, of course, would depend on whether your hosting company allowed wildcard subdomains.
Here is an example of simple subdomain URL rewriting:
strServer = lcase(Request.ServerVariables("SERVER_NAME"))You need to add (or include) this to the beginning of each script that you want to use the subdomain(s) as parameters. Make sure you change mydomain.com to your own domain name (don't include any http:// or www.) and duplicate the line for any additional domain names that might also be used.
' Change mydomain.com to your domain name and duplicate
' this line for additional domain names
strServer = Replace(strServer, "mydomain.com", "")
If strServer = "" Then strServer = "."
strParams = Split(strServer, ".")
If intParam > UBound(strParams) Then
RequestSD = ""
RequestSD = strParams(intParam)
Then to retrieve parameters use the RequestSD(parameter_number) function. For example, use RequestSD(0) for the first parameter, RequestSD(1) for the second and so on.
This example also lacks any protection against characters that might cause problems. If the parameter had a . (full stop) or a / (forward slash) in it then it will cause problems. You are best to pass only text or numbers and perhaps a few other symbols like the minus sign.
Update: There are now other ways to do this that might be simpler, for example the IIS7 URL Rewrite Module. However, the custom error page option can possibly give you more control.
by John Avis | May 6, 2020
If you are having intermittent problems sending email in .NET using System.Net.Mail consider switching libraries.
by John Avis | November 4, 2019
As support ends for Microsoft Windows Server 2008 I have recently gone through migrating some websites to a new server running Windows Server 2016 and IIS 10 but some of the websites did not work.
by John Avis | October 15, 2019
For a website project I needed a way to enter multiple tags. I just wanted something simple that I could easily modify to suit my own needs, so I wrote my own.