Contact Us Forum Rules Search Archive
WebProWorld Part of WebProNews.com
Page One Link To Us Edit Profile Private Messages Archives FAQ RSS Feeds  
 

Go Back   WebProWorld > Webmaster, IT and Security Discussion > Web Programming Discussion Forum
Subscribe to the Newsletter FREE!


Register FAQ Members List Calendar Arcade Chatbox Mark Forums Read

Web Programming Discussion Forum Working with an API? Developing a plugin? Writing a Mod or script for your favorite blog, Web 2.0 site or Forum? Welcome.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-26-2007, 03:12 PM
rumblepup's Avatar
Moderator
WebProWorld Moderator
 

Join Date: Jul 2003
Location: Miami, Florida
Posts: 323
rumblepup RepRank 2
Default ASP dynamic 301 redirect based on Product ID

I've been going nuts about this for awhile, but I just can't find the answer. I'm not a coder, but a script scraper, so I'm dead if I can't do this.

I'm changing a site over from asp to asp.net. One of the problems I'm having is 301 redirecting all of the dynamic urls to their new counterparts. There was only one constant I was able to maintain in the dabase migration, and it was the product table UID (ID's) Those are all the same and the basis for product navigation in both applications.

Well here is my problem. I need to do a 301 redirect from three files:

1. default.asp: (No problem really, just giving you background)

2. prodList.asp: Which are the Category Navigation pages. These look like this:
prodList.asp?idCategory=26

and finally
3. prodView.asp: which is the product detail view.
These look like this:
prodView.asp?idproduct=418

Ok.
For default.asp, just a 301 redirect. Found it here in the forums, no problem.

For prodList.asp, I have to 301 redirect to a corresponding Category page which looks like
SearchResult.aspx?CategoryID=(ID)

I have to do these by hand because the Category ID's are not consistent. I had to re-categorize for better SEO.
So how do I construct an IF/Then statement for the following logic
IF
prodlist.asp?idCategory=(ID)
then redirect to
SearchResult.aspx?CategoryID=(ID)
IF Not
Then
IF
And so on.

And then there is the prodView.asp page. I have to redirect these to like this
prodView.asp?idproduct=(UID)
detail.aspx?=ID(UID)
both the UID numbers will be the same number.

I'm hoping that I can do this with a couple of lines of code , to make life easier for myself.

Any help. Please! Please! Please! Please!
(I ain't to proud to beg)
Reply With Quote
  #2 (permalink)  
Old 04-26-2007, 03:46 PM
incrediblehelp's Avatar
Moderator
WebProWorld Moderator
 

Join Date: Jan 2004
Location: Live in Cincy Now
Posts: 7,702
incrediblehelp RepRank 4incrediblehelp RepRank 4incrediblehelp RepRank 4incrediblehelp RepRank 4
Default

So you don't want to simply list all the old URLs in the htaccess file with the corresponding new URLs?

Your trying to do this with a wildcard somehow?
Reply With Quote
  #3 (permalink)  
Old 04-26-2007, 03:56 PM
rumblepup's Avatar
Moderator
WebProWorld Moderator
 

Join Date: Jul 2003
Location: Miami, Florida
Posts: 323
rumblepup RepRank 2
Default

Quote:
So you don't want to simply list all the old URLs in the htaccess file with the corresponding new URLs?
IIS hosting. Doesn't have cool htaccess


Quote:
Your trying to do this with a wildcard somehow?
Nope. With the prodlist.asp page I'll be manually coding 301 redirect from old Category ID to new Category ID....problem is, I don't know how.

With prodview.asp, kinda sorta.
The one constant, as I said, is the product UID. So even though the page name is different, the ID's are the same.

So the argument is
IF
prodView.asp?idproduct=(querystringID)
then
detail.aspx?=ID(querystringID)
Reply With Quote
  #4 (permalink)  
Old 04-26-2007, 05:46 PM
rumblepup's Avatar
Moderator
WebProWorld Moderator
 

Join Date: Jul 2003
Location: Miami, Florida
Posts: 323
rumblepup RepRank 2
Default

Ok, how about this. Instead of pointing a product display page to the corresponding product display page in the new ap, what if I point all of the old product pages to a special page I have called all products, which is a list of all active products.
Reply With Quote
  #5 (permalink)  
Old 04-26-2007, 06:11 PM
WebProWorld New Member
 

Join Date: Sep 2005
Posts: 4
blac6789 RepRank 0
Default isapi rewrite

If your urls have some sort of pattern to the conversion you can use a tool called isapi rewrite. I use it to make my urls for our shopping cart users more search engine friendly but you could also use it to do the redirect like this. Conversely just make a delimited text file and read it in from your not found page and if it finds a matching url it goes to the new page perhaps??
__________________
Shopping cart software and ecommerce solutions
http://www.easystorecreator.com
Reply With Quote
  #6 (permalink)  
Old 04-26-2007, 06:16 PM
rumblepup's Avatar
Moderator
WebProWorld Moderator
 

Join Date: Jul 2003
Location: Miami, Florida
Posts: 323
rumblepup RepRank 2
Default

ISAPI rewrite not available.
Reply With Quote
  #7 (permalink)  
Old 04-27-2007, 12:56 AM
ADAM Web Design's Avatar
WebProWorld 1,000+ Club
 

Join Date: Dec 2003
Location: Toronto, Ontario, Canada
Posts: 2,217
ADAM Web Design RepRank 0
Default

If you can get a custom 404 installed, you can do it that way.

What you do is you set up the 404 to gather the URL, including the querystring. Then you'd extract the querystring and redirect to the new URL.

I don't have a code sample whipped up to show you the gathering of an old URL to a new URL (since that's situation-specific), but I do have some generic ASP 301 code here:

http://www.walkonmypath.com/asp-301-redirect-code/

(It's the proper 301 code too...battle-tested to the hilt.)
Reply With Quote
  #8 (permalink)  
Old 04-27-2007, 03:04 AM
WebProWorld Member
 

Join Date: Jan 2007
Location: India
Posts: 38
ddwebguru RepRank 0
Default

use it for 301 redirection from .asp page to .aspx page > write it in old .asp page

<%@ Language=VBScript %>
<%
Response.Status="301 Moved Permanently"
Response.AddHeader "Location", "http://www.yourdomain.com/yourpage.aspx"
%>

I think you can made it.
Reply With Quote
  #9 (permalink)  
Old 04-27-2007, 09:17 AM
WebProWorld New Member
 

Join Date: Nov 2005
Posts: 9
tim2005 RepRank 0
Default

Use this code for default.asp
Code:
<%@ Language=VBScript %>
<%
Response.Status="301 Moved Permanently"
Response.AddHeader "Location", "http://www.yourdomain.com/default.aspx"
Response.End
%>
Use this code for prodlist.asp
Code:
<%@ Language=VBScript %>
<%
Dim CategoryID
CategoryID = Request.QueryString("idCategory")

'Here you can insert some processing for category ID if you need
If IsNumber(CategoryID) Then
	CategoryID = CLng(CategoryID)
Else
	'Some default category
	CategoryID = 111
End If

If CategoryID = 1 Then
	CategoryID = 10
ElseIf CategoryID = 2 Then
	CategoryID = 22
End If
'Here you can insert some processing for category ID if you need

Response.Status="301 Moved Permanently"
Response.AddHeader "Location", "http://www.yourdomain.com/SearchResult.aspx?CategoryID=" & CStr(CategoryID)
Response.End
%>
Use this code for prodView.asp
Code:
<%@ Language=VBScript %>
<%
Dim ProductID
ProductID = Request.QueryString("idproduct")
'Check the ID
If Not IsNumber(ProductID) Then
	ProductID = "111" 'Some default product
End If
'Check the ID

Response.Status="301 Moved Permanently"
Response.AddHeader "Location", "http://www.yourdomain.com/detail.aspx? ID=" & ProductID
Response.End
%>
I suppose it should work.
Reply With Quote
  #10 (permalink)  
Old 04-27-2007, 10:42 AM
rumblepup's Avatar
Moderator
WebProWorld Moderator
 

Join Date: Jul 2003
Location: Miami, Florida
Posts: 323
rumblepup RepRank 2
Default

You my friend....ARE AN ANIMAL!!!

The script works GREAT!

One problem I found,

<%@ Language=VBScript %>
<%
Dim ProductID
ProductID = Request.QueryString("idproduct")
'Check the ID
If Not IsNumber(ProductID) Then
SHOULD BE
If Not IsNumeric(ProductID) Then
ProductID = "111" 'Some default product
End If
'Check the ID

Response.Status="301 Moved Permanently"
Response.AddHeader "Location", "http://www.yourdomain.com/detail.aspx? ID=" & ProductID
Response.End
%>


Other than that.

OMG, now I can relax, throw back a Cuba Libre and a Glazed donut.

Thank you! Thank you! Thank you! Thank you! Thank you!
Reply With Quote
  #11 (permalink)  
Old 04-27-2007, 11:12 AM
rumblepup's Avatar
Moderator
WebProWorld Moderator
 

Join Date: Jul 2003
Location: Miami, Florida
Posts: 323
rumblepup RepRank 2
Default

Now this is terrible.

Just found one other parameter:

prodList.asp?brand=(a brand name)

Now, I can redirect these as well, based on a name, to this

searchresults.aspx?Keywords=(a brand name)

Any idea

I can add
Dim Brand
Brand = Request.QueryString("brand")

but I can't wrap my head around the argument
Reply With Quote
  #12 (permalink)  
Old 04-28-2007, 08:38 AM
WebProWorld New Member
 

Join Date: Nov 2005
Posts: 9
tim2005 RepRank 0
Default

You are welcome :-)

Exact solution depends on how parameters "idCategory" and "brand" are used. I mean page can receive only one parameter or both.

If both parameters are used, just add processing for "brand" parameter:
Code:
<%@ Language=VBScript %>
<%
Dim CategoryID
CategoryID = Request.QueryString("idCategory")
Dim Brand
Brand = Request.QueryString("brand")

'Here you can insert some processing for category ID if you need
If IsNumeric(CategoryID) Then
   CategoryID = CLng(CategoryID)
Else
   'Some default category
   CategoryID = 111
End If

If CategoryID = 1 Then
   CategoryID = 10
ElseIf CategoryID = 2 Then
   CategoryID = 22
End If
'Here you can insert some processing for category ID if you need

Response.Status="301 Moved Permanently"
Response.AddHeader "Location", "http://www.yourdomain.com/SearchResult.aspx?CategoryID=" & CStr(CategoryID) & "&brand=" & Server.URLEncode(Brand)
Response.End
%>
If only one parameter is possible:
Code:
<%@ Language=VBScript %>
<%
Dim CategoryID
CategoryID = Request.QueryString("idCategory")
Dim Brand
Brand = Request.QueryString("brand")
Dim URL
URL = ""

'Check if CategoryID present
If Len(CategoryID) > 0 Then
   'Here you can insert some processing for category ID if you need
   If IsNumeric(CategoryID) Then
      CategoryID = CLng(CategoryID)
   Else
      'Some default category
      CategoryID = 111
   End If

   If CategoryID = 1 Then
      CategoryID = 10
   ElseIf CategoryID = 2 Then
      CategoryID = 22
   End If
   'Here you can insert some processing for category ID if you need
   URL = "http://www.yourdomain.com/SearchResult.aspx?CategoryID=" & CStr(CategoryID)

'Check if Brand present
ElseIf Len(Brand) >0 Then
   URL = "http://www.yourdomain.com/SearchResult.aspx?brand=" & Server.URLEncode(Brand)
Else
   'There are no expected parameters, so place some default search here
   URL = "http://www.yourdomain.com/SearchResult.aspx?brand=defaultbrand"
End If

Response.Status="301 Moved Permanently"
Response.AddHeader "Location", URL
Response.End

%>
Reply With Quote
Reply

  WebProWorld > Webmaster, IT and Security Discussion > Web Programming Discussion Forum
Tags: , , , , ,



Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Search Engine Optimization by vBSEO 3.2.0