Print Page | Close Window

301 Redirect

Printed From: ProductCart E-Commerce Solutions
Category: ProductCart
Forum Name: Customizing ProductCart
Forum Description: Exchange messages with other users that are customizing ProductCart.
URL: https://forum.productcart.com/forum_posts.asp?TID=3308
Printed Date: 20-May-2024 at 2:58am
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: 301 Redirect
Posted By: avalight
Subject: 301 Redirect
Date Posted: 22-December-2009 at 11:12pm
What would be the best way to redirect this asp page:
http://www.avalanche-ranch.com/rusticlighting/pc/viewCategories.asp?idCategory=3

to this page

http://www.avalanche-ranch.com/rusticlighting/pc/viewCategories.asp?idCategory=4

I want to use a 301 redirect.  I have looked online for this.  I don't see a solution.  Perhaps the isapi rewrite?  Looks pretty complicated.  I have just stopped using that category...

Thanks
Curt
Avalanche Ranch Light Company

-------------
Curt



Replies:
Posted By: Greg Dinger
Date Posted: 22-December-2009 at 11:45pm
That's simple Curt.  Just place a bit of code in your header.asp
 
Here is the code that allows you to grab the current page name.
http://www.codeave.com/asp/code.asp?u_log=42 - http://www.codeave.com/asp/code.asp?u_log=42
 
Here is the code for an ASP 301 redirect.
http://www.seoconsultants.com/tips/asp/301.asp - http://www.seoconsultants.com/tips/asp/301.asp
 
You need to wrap the 301 redirect with an IF statement that tests for which page you are on.  When you find that you are on the page you want to redirect from, pull the trigger and blast it.


-------------
GreyBeard Design Group

Certified ProductCart Developer

Web Design/Development/Hosting

http://tinyurl.com/5c8t4t" rel="nofollow - Add-Ons & Custom Code |


Posted By: worldofrugs
Date Posted: 02-June-2010 at 3:26pm
Afraid it's not working for me :(

I tried adding this at the top of the  page:

Dim CatNumber
CatNumber= lcase(Request.ServerVariables("Query_String"))
if CatNumber="idcategory=224" then
Response.Status="301 Moved Permanently"
Response.Redirect "/shop/pc/TheOtherPage.asp"
Response.End()
else
if CatNumber="idcategory=11" then
Response.Status="301 Moved Permanently"
Response.Redirect "/shop/pc/OtherPage2.asp"
Response.End()
end if
end if


While the Re-Direct goes fine, the headr status is not returning 301, but 302!
Any suggestions?


Posted By: worldofrugs
Date Posted: 02-June-2010 at 4:19pm
Never mind... Figured it out... Should have used:
Response.AddHeader "Location", "/shop/pc/OtherPage.asp" instead of the Respnse.Redirect

Time for more coffee!! Embarrassed


Posted By: Brett
Date Posted: 03-June-2010 at 1:20am
You might be able to find the category by simply doing:

<% if pIdCategory="number you want" then %>

Since viewcategories.asp is already populating that variable


Posted By: worldofrugs
Date Posted: 03-June-2010 at 9:50am
Thanks for that tip Brett!  Will try this out today and when it works (asuming it does), it will keep the coding a little cleaner
Thanks!
Clap


Posted By: Greg Dinger
Date Posted: 03-June-2010 at 9:59am
Paul, on another note, you should make it a general practice to sanitize your reference to querystring values.  Whether the resulting value is sent to a query or not, use the "getuserinput" function.  Were you to not do so when sending a  querystring value to a query, you would create a security hold that could be deadly.
 
http://wiki.earlyimpact.com/how_to/sanitize_strings?s%5b%5d=getuserinput - http://wiki.earlyimpact.com/how_to/sanitize_strings?s[]=getuserinput
 
In your example above, the following statement would cause you massive grief "catnumber" was sent to a query and a hacker discovered it.
 
CatNumber= lcase(Request.ServerVariables("Query_String"))


-------------
GreyBeard Design Group

Certified ProductCart Developer

Web Design/Development/Hosting

http://tinyurl.com/5c8t4t" rel="nofollow - Add-Ons & Custom Code |


Posted By: worldofrugs
Date Posted: 03-June-2010 at 10:26am
Thanks for that tip Greg...
However, as I am not a programming guru, I'm not sure how to implement this in my situation.

I have quickly tried:
Dim idCategory
idCategory = getUserInput(Request("id"),5)
if idCategory="224" then
Response.Status="301 Moved Permanently"
Response.AddHeader "Location", "/shop/pc/TheOtherPage.asp"
Response.End()
end if


but this does not work. It simply goes to the "msg.asp?message=86" page (not a valid category), not resulting in the redirect I want and not returning the 301 header status.

Did I miss something?


Posted By: worldofrugs
Date Posted: 03-June-2010 at 10:30am
Never mind Greg, I found the issue.
On the Wiki page you gave me, you have the line:
Dim idCategory
idCategory = getUserInput(Request("id"),5)


But it should actually be:
Dim idCategory
idCategory = getUserInput(Request("idCategory "),5)


When I changed it this way, working great, so I assume that this is the best way to go?
Thanks for pointing it out Greg, 'you tha man'! Wink


Posted By: Greg Dinger
Date Posted: 03-June-2010 at 10:33am
That's what I had in mind.  You DO NOT want to wake up one day and receive reports that the store has been attacked.  Concientious use of proper protection methods is absolutely critical.

-------------
GreyBeard Design Group

Certified ProductCart Developer

Web Design/Development/Hosting

http://tinyurl.com/5c8t4t" rel="nofollow - Add-Ons & Custom Code |


Posted By: worldofrugs
Date Posted: 03-June-2010 at 10:39am
Thanks for the help Greg. I'm implementing the pages that need to be re-directed right now and it works as it should.
It's a good feeling to know that I'm "safe" now
Thanks!!!


Posted By: Brett
Date Posted: 03-June-2010 at 1:45pm
Isn't the native ProductCart variable pIdCategory category already sanitized?

*edit*

Not to confuse anyone... Greg's solution is completely secure and I'm sure the processor overhead for such a simple calculation is minimal. However, it seems a bit redundant to have two variables holding the same number.


Posted By: Greg Dinger
Date Posted: 03-June-2010 at 2:50pm
I was responding to the code he posted and wanted to point out the importance that when he is dealing directly with querstring variables the need for caution.

-------------
GreyBeard Design Group

Certified ProductCart Developer

Web Design/Development/Hosting

http://tinyurl.com/5c8t4t" rel="nofollow - Add-Ons & Custom Code |


Posted By: worldofrugs
Date Posted: 19-August-2010 at 2:38pm
Additional question to this issue...
While the given code works perfectly (thanks Greg!), I'm wondering if the following would be an option.

Say I have 5 categories: 120/121/122/123/124
I could write the code for each single line, but could it be made more simple by doing something like:
If idCategory >119 AND idCategory < 125 Then
.... [action to be taken] .....

I know I prob. have to convert the string to a number, but not sure on these things.
Somehow I have a feeling this should be simple to do?

It sure would save a lot of coding!

------ EDIT ------
Found the solution Wink

Dim idCategory
idCategory = Cint(getUserInput(Request("idCategory"),5))
if idCategory>119 AND idCategory<125 then
.... [action to be taken] .....



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net