Clicky

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

asked 09/08/2011 10:02

coreybryant's gravatar image

coreybryant ♦♦


8 Answers:
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.

1:
2:
3:
4:
5:
6:
7:
8:
# 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]


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:

1:
2:
3:
4:
5:
6:
7:
# 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
link
routinet's gravatar image

routinet

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.  
link
coreybryant's gravatar image

coreybryant

>>> I have Helicon ISAPI Rewrite installed on the server.

You said you have Helicon's ISAPI Rewrite installed...?
link
routinet's gravatar image

routinet

Yes, Helicon ISAPI re-write is installed.
link
coreybryant's gravatar image

coreybryant

Then my previous comment stands.
link
routinet's gravatar image

routinet

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!
link
coreybryant's gravatar image

coreybryant

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

1:
2:
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
link
routinet's gravatar image

routinet

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
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

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
1:
2:
3:
4:
5:
6:
# Helicon ISAPI_Rewrite configuration file
# Version 3.1.0.32 

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

Thank you!
link
coreybryant's gravatar image

coreybryant

Your answer
[hide preview]

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Tags:

×1
×1

Asked: 09/08/2011 10:02

Seen: 618 times

Last updated: 10/08/2011 03:55