Welcome to WebmasterWorld Guest from 22.214.171.124
Forum Moderators: ocean10000
I want to 301 redirect pages using the below code on a custom 404 page, so that the code checks to see if its on a specific old URL, and if it is redirect to a new URL.
I'd like to check two things - first of all does the below code look ok?
JScript 404 Page Redirector
var oldURL = new Array();
var newURL = new Array();
var strDomain = "http://www.example.com";
var strRedirect = "/";
var strPath = String(Request.QueryString());
oldURL = '/site/example1';newURL = '/example1';
oldURL = '/site/example2';newURL = '/example2';
oldURL = '/site/example3';newURL = '/example3';
oldURL = '/site/example4';newURL = '/example4';
oldURL = '/site/example5';newURL = '/example5';
for ( var i = 0; i < oldURL.length; i++)
if (strPath.indexOf( oldURL[i] ) != -1 )
strRedirect = newURL[i];
strRedirect = strDomain + strRedirect;
Response.Status = "301 Moved Permanently"
Response.AddHeader ("Location", strRedirect);
And what would be the best way to implement it? Should the code above print out HTML in addition, or can I just embed it on a custom 404 page in the site template?
Many many thanks if you can help, I'll shower you in praise and kudos! :)
[edited by: eelixduppy at 1:41 am (utc) on Feb. 10, 2009]
[edit reason] exemplified [/edit]
You need to check whether the old URL is matched, and if so do the 301 *else* return 404.
Also you need to check how the 404 page is setup in IIS. Depending on how it is configured IIS may return a 302 response first then the error page's status. Can't remember exact details but you can check your script works as expected with the LiveHTTPHeaders extension for Firefox.