|
|
||||||
|
||||||
| Index Link To US Private Messages Archive FAQ RSS | ||||||
| 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. |
Share Thread: & Tags
|
||||
|
![]() |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
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) |
|
|||
|
Quote:
Quote:
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) |
|
|||
|
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.
|
|
|||
|
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??
|
|
|||
|
ISAPI rewrite not available.
|
|
||||
|
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.)
__________________
Toronto Web Design | Search Engine Friendly, Standards-Compliant Layouts | Walk on my Path (my blog) |
|
|||
|
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. |
|
|||
|
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 %> 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
%>
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
%>
|
|
|||
|
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! |
|
|||
|
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 |
|
|||
|
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
%>
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
%>
|
![]() |
|
| Thread Tools | |
| Display Modes | |
|
|
|
WebProWorld |
Advertise |
Contact Us |
About |
Forum Rules |
MVP's |
Archive |
Newsletter Archive |
Top |
WebProNews
WebProWorld is an iEntry, Inc. ® site - © 2009 All Rights Reserved Privacy Policy and Legal iEntry, Inc. 2549 Richmond Rd. Lexington KY, 40509 |