Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2011-09-08
8
Medium Priority
?
723 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 51

Accepted Solution

by:
Steve Bink earned 2000 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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 2000 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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

If you are a web developer, you would be aware of the <iframe> tag in HTML. The <iframe> stands for inline frame and is used to embed another document within the current HTML document. The embedded document could be even another website.
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

963 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