Solved

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

Posted on 2011-09-08
8
711 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
8 Comments
 
LVL 51

Accepted Solution

by:
Steve Bink earned 500 total points
ID: 36514815
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
ID: 36593190
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 51

Expert Comment

by:Steve Bink
ID: 36593323
>>> I have Helicon ISAPI Rewrite installed on the server.

You said you have Helicon's ISAPI Rewrite installed...?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 29

Author Comment

by:coreybryant
ID: 36712955
Yes, Helicon ISAPI re-write is installed.
0
 
LVL 51

Expert Comment

by:Steve Bink
ID: 36712986
Then my previous comment stands.
0
 
LVL 29

Author Comment

by:coreybryant
ID: 36713316
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 51

Assisted Solution

by:Steve Bink
Steve Bink earned 500 total points
ID: 36714431
>>> 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
ID: 36893782
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Determining the an SCCM package name from the Package ID
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Suggested Courses

628 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