Pages: [1]
Print
Author Topic: New feature: URL Rewriting in ASP...  (Read 1103 times)
Phillipe Calmet Williams
Jr. Member
**
Posts: 50



View Profile WWW
« on: October 29, 2009, 12:35:43 PM »

Hi there...

I've found a nice script that can help us do some URL rewriting in ASP.

What is it's purpose? Well, to be able to enter an address like this:
Code:
http://www.ford.com/explorer/1999/

instead of this:
Code:
http://www.ford.com/page.asp?model=explorer&year=1999

Here is the link for the tutorial: http://asp.johnavis.com/blog/default.asp?id=19
« Last Edit: June 17, 2010, 11:46:38 PM by Phillipe Calmet Williams » Logged

Tonkow
Newbie
*
Posts: 29


www.tonkow.se/eng

msn@tonkow.se
View Profile WWW Email
« Reply #1 on: November 27, 2009, 10:39:00 AM »

AWESOME!
Thx
Logged

Love it!
Phillipe Calmet Williams
Jr. Member
**
Posts: 50



View Profile WWW
« Reply #2 on: June 07, 2010, 12:24:45 PM »

I've just found another (and i think better) script that can help us use "friendly URLs" with Classic ASP.

http://evolt.org/search_engine_friendly_urls_with_iis_and_classic_asp

I am sure (and hope) this can (somehow) be implemented into the BP blog system.

Note: just make sure you have access to the IIS in your server to create the custom error.
Logged

Phillipe Calmet Williams
Jr. Member
**
Posts: 50



View Profile WWW
« Reply #3 on: June 07, 2010, 01:43:25 PM »

Update: My blog is now using friendly URLs  Grin

Check them at: www.elflip.info.. (the blog is in spanish)
Logged

Phillipe Calmet Williams
Jr. Member
**
Posts: 50



View Profile WWW
« Reply #4 on: June 07, 2010, 02:09:41 PM »

Update: Here is the code i am using in my blog:

Code:
<%

Dim RQ, P, ID, ID2

RQ = Request.QueryString
ErrorFound = False

P = Instr(RQ,"article/")
If P > 0 Then
DoProperLink 8, "template_permalink"
Else
P = Instr(RQ, "page/")
If P > 0 Then
DoProperLink 5, "template"
Else
P = Instr(RQ, "cat/")
If P > 0 Then
DoProperLink 4, "template_archives_cat"
Else
P = Instr(RQ, "archives/")
If P > 0 Then
DoProperLink 9, "template_archives"
Else
P = Instr(RQ, "author/")
If P > 0 Then
DoProperLink 7, "template_author"
Else
ErrorFound = True
End If
End If
End If
End If
End If

function DoProperLink(num, aspPage)

  Session("ID") = ""
  Session("ID2") = ""

  RQ = Mid(RQ,P+num)
  P = Instr(RQ, "/")
  If P > 0 Then
    ID = Left(RQ,P-1)
Session("ID") = ID
    RQ = Mid(RQ,P+1)
If aspPage = "template_archives" Then
P = Instr(RQ, "/")
If P > 0 Then
ID2 = Left(RQ,P-1)
Session("ID2") = ID2
Else
ErrorFound = True
End If
End If
  Else
    ErrorFound = True
  End If

  If Not ErrorFound Then
Server.Transfer "/" & aspPage & ".asp"
  Else
Response.Status = "404 File Not Found"
Response.End
  End If
 
end function

%>

And on each page, i've included this code:

Code:
<%
Dim getID
getID = Session("ID")
if getID = "" Then getID = Request.QueryString("id")
%>

You must check if the request of the querystring is for "id". If not, change it (e.g. chosenYear, PageName, etc).

For example, in the "template_archives" file, i've used:

Code:
<%
Dim getID
getID = Session("ID")
if getID = "" Then getID = Request.QueryString("chosenYear")

Dim getID2
getID2 = Session("ID2")
if getID2 = "" Then getID = Request.QueryString("chosenMonth")

%>

And replace all the "request.querystring" in the page for the new variables.


Note: i've used this in BP Blog 8.0.2, which is the one i am using right now. I guess it must be easy to apply it on version 9 also.
Logged

Matt
BP Blog Developer/Musician
Administrator
Newbie
*****
Posts: 36



View Profile WWW Email
« Reply #5 on: June 08, 2010, 06:57:23 AM »

This is really great!  Did you have to change anything on the server side (IIS) or just implement this code? 

I'll integrate this into the next version and then you can just check a box in the admin to enable friendly urls.
Logged

Phillipe Calmet Williams
Jr. Member
**
Posts: 50



View Profile WWW
« Reply #6 on: June 08, 2010, 02:58:24 PM »

Well, in the IIS, i had to create a custom error, as indicated in the tutorial (Step One: 404 Error Handler):

http://evolt.org/search_engine_friendly_urls_with_iis_and_classic_asp

Everything else is just the code.
« Last Edit: June 08, 2010, 03:13:23 PM by phillipecw » Logged

Phillipe Calmet Williams
Jr. Member
**
Posts: 50



View Profile WWW
« Reply #7 on: June 08, 2010, 09:36:43 PM »

Update: i found a "bug" in the code used inside the "template" pages. The code should be:
Code:
<%
Dim getID
getID = Request.QueryString("chosenYear")
if getID = "" Then getID = Session("ID")
%>

This will allow us to still use the "conventional" way to show the posts (template_permalink.asp?id=).

The previous code, since it reads the session value first, it will keep showing the same post when using the "template" page directly, instead of showing the one if the "id" querystring. Changing the order of requests fixed that.

I will be changing it in my blog tomorrow.  Tongue
Logged

Phillipe Calmet Williams
Jr. Member
**
Posts: 50



View Profile WWW
« Reply #8 on: June 09, 2010, 09:47:11 PM »

I'll integrate this into the next version and then you can just check a box in the admin to enable friendly urls.

Just make sure, when this option is active, to "change" all links from "template_permalink.asp?id=00" to (in my case) "/article/00" (where "00" is the id of the post). The same for all other pages.
Logged

Pages: [1]
Print
Jump to: