Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

301 Redirect without .htaccess file 1

Status
Not open for further replies.

ecobb

Programmer
Dec 5, 2002
2,190
US
I have an existing website that used to consisit of .htm pages. Very small site, only about 5 .htm pages. The site has been redesigned and the design now consists of ColdFusion pages. (.cfm pages replacing .htm pages) On some of the pages the content is the same, on some it's not. For example, contact.htm and contact.cfm have identical content.

Anyway, the site is on a Win shared hosting plan, and I can't use .htaccess and the host doesn't support 301 redirects in IIS. The old site has some pretty good SE rankings, and I don't want to lose that, so here's my plan (tell me if I'm wrong!).

1) Put the new .cfm files out there (but don't delete the existing .htm files), remove links to any .htm files, and leave it alone for a while, until the Search Engines have had time to index the new stuff.

2) When I put the new .cfm file out, change the links in the nave menu in the .htm files to point to the new .cfm files, so if anyone comes to the site via the old pages, they still navigate to the new stuff.

3) After the Search Engines have had time to index the new stuff, put a Disallow in my robots.txt for the .htm pages, effectively (eventually) removing them from the Search Engines and only the new .cfm stuff is left. Also put a meta redirect on the .htm pages to the correct page, in case anyone comes to it.

Remember, we're only talking about 5 .htm files, and I can leave them on the server forever if need be.

Whadaya think? Will this work, or am I wasting my time?

Hope This Helps!

ECAR
ECAR Technologies

"My work is a game, a very serious game." - M.C. Escher
 
Hi

Just thinking aloud, I do not know neither ColdFusion or IIS. I hope this solutions can be done with them too.
[ul]
[li]Write a ColdFusion script called contact.htm which to only send the redirection to contact.cfm.[/li]
[li]Configure IIS to execute *.htm files as ColdFusion scripts.[/li]
[/ul]
Or
[ul]
[li]Write a ColdFusion script which to send a redirection to the file for which it was called, but the extension changed from .htm to .cfm.[/li]
[li]Configure IIS to execute that file when a 404 error occures.[/li]
[/ul]

Feherke.
 
Hi,

I have a very similar issue - but with .ASP pages as opposed to .CFMs.

I also do not have enough access to the IIS (we're on shared hosting) to modify it simply.

Apologies for linking away from this great site, but there's a similar thread here:

And I understand how a Custom 404 error page could work, but I can't get it working! Maybe someone can help, here's the code:

Code:
dim i, newURI, req, pageArray(1,50)

pageArray(0,0) = "accessibility.htm"
pageArray(1,0) = "accessibility.asp"

req = replace(request.servervariables("QUERY_STRING"),"404;","")

bFound = false

for i = 0 to ubound(pageArray,2)
    if instr(req, pageArray(0,i)) > 0 then
       	'newURI = replace(req,pageArray(0,i),"newdir/" & pageArray(1,i))
		newURI = replace(req,pageArray(0,i), pageArray(1,i))
       	bFound = true
     end if
if bFound then exit for
next

if bFound then
' uncomment the next line to keep the original URI but show the new content
'server.transfer("/newdir/" & pageArray(1,i))
'server.transfer(pageArray(1,i))
' uncomment the next lines to redirect to the new pagename
   response.status = "301 Moved Permanently"
   response.addheader "Location", newURI
   response.end()
else
   response.status = "404 Not Found"
end if

My questions are:
1. Should I delete the HTM file so that the 404 is triggered as it isn't currently?
2.I've been under the impression that the 301 is search engine un-friendly, and the whole point of this exercise is to transfer a PageRank from the HTM to the ASP version...is this correct.

At present this code (which is in my 404.asp page) doesn't get triggered, I just get the 404 page.

Thanks in advance,

Rob

lastdonuk
Health-on-Line
 
Hi

Rob said:
1. Should I delete the HTM file so that the 404 is triggered as it isn't currently?
Yes, otherwise that .htm file will be sent back.
Rob said:
2.I've been under the impression that the 301 is search engine un-friendly, and the whole point of this exercise is to transfer a PageRank from the HTM to the ASP version...is this correct.
No, 301 is search engine friendly. Yes, the point is to provide continuity, including the page rank.
Rob said:
At present this code (which is in my 404.asp page) doesn't get triggered, I just get the 404 page.
You have to configure the server to execute that script if a HTTP 404 error occurs. Done that ?

Feherke.
 
Hi Feherke,

Thanks very much for replying so quickly and with excellent answers. The code I posted sits in my custom 404.asp with which I have replaced the standard 404.htm.

Thanks - I'll go back over my code,

Rob

lastdonuk
Health-on-Line
 
Hi again Feherke,

I've tested my script with the following info in the pageArray:

Code:
pageArray(0,0) = "accessibility.htm"
pageArray(1,0) = "accessibility.asp"

Accessibility.htm no longer exists but I'm now receiving an offer to "Save File" popup in Firefox (possibly a message warning that you're trying to open ASP in an HTM file?).

Incidentally, I've also used absolute links on the page and got the same issue. Do you have any ideas? I feel close to a solution now...

Thanks for any further help you can give,

Rob

lastdonuk
Health-on-Line
 
Hi

That usually happens when the server does not sent a correct [tt]Content-type[/tt] HTTP header to the browser. In FireFox you can see the HTTP headers with the LiveHTTPHeaders extension. If the [tt]Content-type[/tt] header is missing from the response, or its value is not "[tt]text/html[/tt]", then try adding such header line to your ASP script.

Feherke.
 
you probably have the 404 error Message Type set to File and it needs to be URL to run the script.


In IIS MMC;
site properties -> Custom Errors tab -> select 404 -> Click Edit Properties -> select URL from the dropdown -> type the page name into the text box.

Or get your host to set this for you.


Chris.

Indifference will be the downfall of mankind, but who cares?
Woo Hoo! the cobblers kids get new shoes.
People Counting Systems

So long, and thanks for all the fish.
 
Thanks guys,

Feherke - I've added that info into the head of my custom error page - that's good to you, I'll let you know.

Chris - thanks so much for this info, unfortunately I don't seem to be able to update the custom error pages from my ISP's cutdown version of IIS. I can try, but it doesn't update, so I'll await their response. You may recognise your script too, Chris, your help has been so invaluable - thanks...

I'll update you with hopefully good news.

Thanks again,

lastdonuk
Health-on-Line
 
Hi

Please note that my [tt]Content-type[/tt] related suggestion is only based on the symptom. Is just a general thing, I do not know IIS.

Better continue on Chris's suggestion.

Feherke.
 
Hey Feherke,

Ok, thanks, I've added the line into the head anyway.

I've posted the ASP which is in my Custom Error page, in case there's anything glaringly obvious:

Code:
<%
dim i, newURI, req, pageArray(1,50)

pageArray(0,0) = "about/accessibility.htm"
pageArray(1,0) = "about/accessibility.asp"

req = replace(request.servervariables("QUERY_STRING"),"404;","")

bFound = false

for i = 0 to ubound(pageArray,2)
    if instr(req, pageArray(0,i)) > 0 then
       	newURI = replace(req,pageArray(0,i), pageArray(1,i))
       	bFound = true
     end if
if bFound then exit for
next

if bFound then
' uncomment the next line to keep the original URI but show the new content
'server.transfer("/newdir/" & pageArray(1,i))
'server.transfer(pageArray(1,i))
' uncomment the next lines to redirect to the new pagename
   response.status = "301 Moved Permanently"
   response.addheader "Location", newURI
   response.end()
else
%>
HTML body
<%
   response.status = "404 Not Found"
end if
%>

Incidentally, I've also tried with absolute URLs to no avail.

For my testing the file "about/accessibility.htm" no longer exists, hence the need to redirect in a search engine friendly way to it's ASP equivalent.

However, now when I try to go to about/accessibility.htm, I get the warning message asking me if I want to open accessibility.htm or Save the file (in Firefox), like it won't redirect.

Chris, sorry to ask you to look over your code used in my example, but I thought you might have the best idea of how to resolve this...

The latest development is that the record in IIS/Custom Errors now shows:
HTTP Error
404
Type
URL
Contents
/404.asp

And I get this error message in Firefox:
"The page isn't redirecting properly
Firefox has detected that the server is redirecting the request for this address in a way that will never complete."

Thanks again for your help,

Rob

lastdonuk
Health-on-Line
 
Hi Chris,

Thanks for getting back to me and for the links which I will follow.

I've got the script working with only 2 remaining issues:

1. I noticed the request.servervariables("QUERY_STRING") has :80 appended to it, and with the path amended, ie. ":80/accessibility.htm" this redirects perfectly to the ASP

2. If I search for a misspelt or nonexistent page, the code gets caught in a loop.

I'm looking at these now, but if you have any ideas, please let me know!

Cheers

lastdonuk
Health-on-Line
 
Follow up to Point 1 above: Resolved. :80 (Port 80) showed up in the query string and I assumed it was needed, but the following standard convention works fine:

"about/accessibility.htm"

Point 2 is still WIP...

Cheers

lastdonuk
Health-on-Line
 
Rejig of code

Code:
<%
dim i, newURI, req, pageArray(1,50)

pageArray(0,0) = "about/accessibility.htm"
pageArray(0,1) = "about/accessibility.asp"

bFound = false
for i = 0 to ubound(pageArray,1)
    if instr(request.servervariables("QUERY_STRING"), pageArray(0,i)) > 0 then
		req = replace(request.servervariables("QUERY_STRING"),"404;","")
          newURI = replace(req,pageArray(i,0), pageArray(i,1))
           bFound = true
     end if
if bFound then exit for
next
if bFound then
' uncomment the next line to keep the original URI but show the new content
'server.transfer("/newdir/" & pageArray(1,i))
'server.transfer(pageArray(1,i))
' uncomment the next lines to redirect to the new pagename
   response.status = "301 Moved Permanently"
   response.addheader "Location", newURI
   response.end()
else
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">[/URL]
<html>
<head>
<title>Not Found</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
This is the 404 page 
<body>
</body>
</html>

<%
   response.status = "404 Not Found"
end if
%>

I'll go and edit it at HR as well :D

Chris.

Indifference will be the downfall of mankind, but who cares?
Woo Hoo! the cobblers kids get new shoes.
People Counting Systems

So long, and thanks for all the fish.
 
Hey Chris,

Thanks - I thought that was it all done, but...

If I search for:

I still get that Timeout/loop issue in the browser, is it something to do with the "bFound next" part of the code?

WebBug shows me a 301...should be 404, see Header below:

HTTP/1.1 301 Moved Permanently
Connection: close
Date: Thu, 22 Feb 2007 15:34:09 GMT
Server: Microsoft-IIS/6.0
MicrosoftOfficeWebServer: 5.0_Pub
X-Powered-By: ASP.NET
Location: Content-Length: 0
Content-Type: text/html
Set-Cookie: ASPSESSIONIDQCSQAQSS=CNIDGHCBOLPDOBDEANEFGJOE; path=/
Cache-control: private

Sorry I can't debug better and help you out...what you posted above makes perfect sense to me, I'll keep looking too.

Nice move to update HR too - that was the only place I could find ANY reference to this issue when I Googled for it.

Cheers

lastdonuk
Health-on-Line
 
Chris - it works fine (of course) - your new code is perfect.

Thanks so much for this and sorry to drag you over your own code again.

This is the solution to my problem, I'm not sure it deserves a FAQ of it's own or even how to do it - it IS your solution after all ;)

Have a star, anyway, this is working excellently now.

Cheers again!

lastdonuk
Health-on-Line
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top