Solved

Using ISAPI Re-write for ASP.NET and ASP Pages

Posted on 2011-09-08
8
670 Views
Last Modified: 2012-05-12
I have Helicon ISAPI Rewrite installed on the server.  I will be using a .NET script.  

A script that I am looking at creates pages like this:
http://www.myasp-net.com/directory/pageview.aspx?tab=1&catid=7&subid=77
to
http://www.example.com/directory/merchant-accounts
If someone were to click on that link, can that URL be displayed instead to read something a bit easier (for SEO purposes)?  

I know on my blog I have them being re-written but they point to the specific link
http://www.example.com/2010/08/comparing-electronic-payment-gateways
instead of something like:
http://www.example.com/permalink.asp?123

I also have links to something like:
http://www.example.com/links/507.asp

Can something easily be added to change that link to
http://www.example.com/links/merchant-accounts

with the ISAPI Helicon rewrite instead of pointing the URLs to
0
Comment
Question by:coreybryant
  • 4
  • 4
8 Comments
 
LVL 50

Accepted Solution

by:
Steve Bink earned 500 total points
Comment Utility
You can, but it is seriously inefficient to do it this way.  I have not use ISAPI Rewrite in awhile, but I remember it is very similar to mod_rewrite.  I'll use that syntax in my example.

# if the "ugly" URL is used, force a redirect to the "pretty" URL
RewriteCond %{QUERY_STRING} tab=1 [NC]
RewriteCond %{QUERY_STRING} catid=7 [NC]
RewriteCond %{QUERY_STRING} subid=77 [NC]
RewriteRule /?directory/pageview.aspx http://mydomain.com/directory/merchant-accounts [R=301]

# if the "pretty" URL is detected, internally rewrite it to be useful
RewriteRule /?directory/merchant-accounts /directory/pageview.aspx?tab=1&catid=7&subid=77 [NC,QSA]

Open in new window


The order is important here.  The first rule and associated conditions look the "ugly" URL.  If it finds it, it forces a redirection to the "pretty" URL.  On the client side, they will see the new request in their browser's address bar.  The second rule looks for the "pretty" URL and rewrites it to the "ugly" URL.  The client will still see the "pretty" URL in their address bar.

Note that this only handles a single page, and this is difficult to turn into a system with something like RewriteMap due to the variety of checks and external redirection.  To handle additional pages, you would need to create a series of sets just like this.  Put all of the redirection rules at the top, followed by all the internal rewrites.  For example:

# check for ugly URL 1
# check for ugly URL 2
# check for ugly URL 3

# check for pretty URL 1
# check for pretty URL 2
# check for pretty URL 3

Open in new window

0
 
LVL 29

Author Comment

by:coreybryant
Comment Utility
Thank you.  Do you have another option?  I think I am on IIS 6 for the server (I asked a few weeks ago about the IIS rewrite but they said that was not available.  
0
 
LVL 50

Expert Comment

by:Steve Bink
Comment Utility
>>> I have Helicon ISAPI Rewrite installed on the server.

You said you have Helicon's ISAPI Rewrite installed...?
0
 
LVL 29

Author Comment

by:coreybryant
Comment Utility
Yes, Helicon ISAPI re-write is installed.
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 50

Expert Comment

by:Steve Bink
Comment Utility
Then my previous comment stands.
0
 
LVL 29

Author Comment

by:coreybryant
Comment Utility
Sorry, I mis-read part of your response (Note that this only handles a single page, and this is difficult to turn into a system with something like RewriteMap due to the variety of checks and external redirection. )  I thought it said something else, that is why I asked.  

I noticed you had some tab 1, catid, and subid, in there so I just wanted to confirm.  If I have http://www.example.com/directory/8-Merchant-Account-Agents-Partners-and-Resellers.asp, how can the URL be changed to http://www.example.com/directory/Merchant-Account-Agents-Partners-and-Resellers.  Another example is http://www.example.com/directory/25-Card-Associations.asp changed to http://www.example.com/directory/Card-Associations

And then http://www.example.com/links/113.asp should be more like http://www.example.com/links/Discover-Card.  http://www.example.com/links/99.asp should be http://www.example.com/links/MasterCard-Worldwide

http://www.example.com/article_view.asp?articleID=3 should be http://www.example.com/articles/Visa-Issues-PCI-Compliance-Date-for-International-Merchant

I did not know if you were pulling some information from the database and if I needed to update the .htaccess file each time a new category / link / article.

Thanks again!
0
 
LVL 50

Assisted Solution

by:Steve Bink
Steve Bink earned 500 total points
Comment Utility
>>> I did not know if you were pulling some information from the database and if I needed to update the .htaccess file each time a new category / link / article.

Without using some automated matching system through RewriteMap, you will need to maintain the .htaccess file yourself.  RewriteMap can use an external program/script, so it is very possible to automate a large part of this.  It will just be a large amount of effort, as well.  If you are using a CMS, it may have this functionality in it already.  The available features and functionality differ with every package, so you will need to research what is available.

As I noted before, the basic idea behind "pretty URL" enforcement is to detect an "ugly" URL and redirect it to the "pretty" version.  At the same time, your application needs the "ugly" URL to identify what resources it should serve.  The basic template is:

# Search for ugly URL and redirect to the pretty version using [R,L] modifiers
# Search for pretty URL and rewrite to the ugly version

All of the examples you referenced can use this approach.  In fact, the examples you listed could all be done using RewriteMap.  Without RewriteMap, the first example would look like this:

RewriteRule /?directory/8-Merchant-Account-Agents-Partners-and-Resellers.asp http://www.example.com/directory/Merchant-Account-Agents-Partners-and-Resellers [R=301,L]
RewriteRule /?directory/Merchant-Account-Agents-Partners-and-Resellers /directory/8-Merchant-Account-Agents-Partners-and-Resellers.asp

Open in new window

0
 
LVL 29

Author Comment

by:coreybryant
Comment Utility
RewriteEngine On
RewriteCompatibility2 On
RepeatLimit 32
RewriteBase 
# unsupported directive: [ISAPI_Rewrite]

#  3600 = 1 hour
# unsupported directive: CacheClockRate 3600


#  Block external access to the httpd.ini and httpd.parse.errors files
RewriteRule ^/httpd(?:\.ini|\.parse\.errors).*$ / [NC,F,O]
#  Block external access to the Helper ISAPI Extension
RewriteRule ^.*\.isrwhlp$ / [NC,F,O]

# Please do not delete or modify this file as your subdomain might not working properly 
RewriteCond %{HTTP:Host} ^(?!www\.)([^.]+)\..+\..+$
RewriteRule (.*) /%1$1 [NC,L]
RewriteRule /?directory/8-Merchant-Account-Agents-Partners-and-Resellers.asp http://www.example.com/directory/Merchant-Account-Agents-Partners-and-Resellers [R=301,L]
RewriteRule /?directory/Merchant-Account-Agents-Partners-and-Resellers /directory/8-Merchant-Account-Agents-Partners-and-Resellers.asp

Open in new window

When I used that, the page was re-directed over to http://www.iana.org/domains/example/

On another page where I am re-writing the links I have
# Helicon ISAPI_Rewrite configuration file
# Version 3.1.0.32 

RewriteEngine on 
RewriteBase /
RewriteRule ^merchant-account$ /merchant-account.asp [NC,L]

Open in new window

Thank you!
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

First of all, clustering IIS is something you should rarely consider doing. In almost all cases, Microsoft Network Load Balancing (NLB) (http://technet.microsoft.com/en-us/library/cc758834(WS.10).aspx) is a much better solution when you need to p…
Running classic asp applications under Windows Server 2008 R2 (x64) and IIS 7 is not as easy as one may think. It took me a while to figure it out while getting error 8002801d a few times. After you install the OS you will need to install the fol…
This video discusses moving either the default database or any database to a new volume.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now