?
Solved

Redirecting pages

Posted on 2004-08-14
7
Medium Priority
?
505 Views
Last Modified: 2013-12-24
Hi,

I'm trying to find out what the most efficient way is to redirect to pages in this scenario:

The initial website for one of my clients was built in HTML.  The client doesn't want the customer to get to a "page not found" error if users access the old urls once the new site goes live.

I really don't want to just add a meta or javascript redirect in all of the old pages, and keep them on the server, and was wondering if anyone knows of a script that could possibly reside in the application.cfm file or if I need to put a redirect in a custom 404 error file on IIS.  

The only problem with the custom 404 error is that I don't think that I can use CF code on that page, and I need to be able to redirect to a specific page based on the page the user is trying to access (ie, the equivalent .cfm page for the previous .htm page), and if the page didn't previously exist, have the solution redirect to the main index page.  

Does that make sense?  If so, can anyone offer a suggestion?
0
Comment
Question by:liltyga
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 5

Expert Comment

by:8riaN
ID: 11803435
This is actually pretty easy if you get to control both IIS and the Cold Fusion Administrator.  Assuming you can, do this:

Open the CF Adminstrator and in "Server>Server Settings>Settings" set the missing template handler to your home page (or whatever).

Open IIS and set the 404 handler for the site (or the virtual directory, or whatever) to a local URL, starting from the webroot, say "/custom404.cfm"

put code like this into custom404.cfm:

<cfset defaultURL="index.cfm"><!--- The default/site root, whatever, set the missing template handler to this URL in the Cold Fusion Administrator. --->
<cfset errCode=GetToken(QUERY_STRING,1,";")>
<cfset newURL=defaultURL>
<cfif errCode NEQ "404">
      Something's rotten in Denmark <!--- If you set up IIS correctly, this would only happen if somebody browsed straight to custom404.cfm --->
</cfif>
<cfset originalURL=GetToken(QUERY_STRING,2,";")>
<cfif originalURL NEQ "">
      <cfset parseURL=REFindNoCase("(.*).htm$",originalURL,1,TRUE)><!--- this needs to get fancier if it's not simply .htm gets changed to .cfm --->
      <cfif ArrayLen(parseURL.pos) GT 1>
            <cfset newURL=mid(originalURL,parseURL.pos[2],parseURL.len[2])&".cfm"><!--- This too --->
      </cfif>
</cfif>
<cflocation url="#newURL#"><!--- if this doesn't exist, the cf engine will just pass them to the home page. --->

Q.E.D.

8riaN
0
 
LVL 17

Expert Comment

by:Tacobell777
ID: 11806720
You really should not fool around with the 404 page, you need to use redirects from within IIS, as it returns the proper status code back to the browser, i.e. a "page moved" = 303 or something, see http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html

Trust me if you fool around with the 404 error page you will run into trouble at a later stage.
0
 
LVL 5

Accepted Solution

by:
8riaN earned 2000 total points
ID: 11807526
Ok, he's right, this ought to be done the right way.

Trouble is, the right way doesn't seem to exist on IIS unless you can redirect the whole domain.  Apache supports a list of URLs to redirect, but apparently IIS doesn't.  So it seems to me you can 1) forget the whole thing; 2) redo the whole site on a new domain and 301 the whole thing; 3) tell IIS to send .htm pages through the cold fusion interpreter (iscf.dll in CF5) and just put the code in there; or 4) rewrite the 404 page to respond with a proper 301 permanent redirect to the new name, and you decide whether to send a proper 404 if you don't find a matching .cfm file instead of going to the home page.

so replace the last line(<cflocation...>) with:
<cfoutput>
<cfheader statuscode="301" statustext="Moved Permanently">
<cfheader name="Location" value="#newURL#">
<html>
<head>
      <title>Object Moved</title>
</head>
<body>
      <h1>Object Moved</h1>
      <p>The page you requested has been moved to: <a href="#newURL#">#newURL#</a></p>
</body>
</html>
</cfoutput>

The good news is, if you don't experience any other horrible calamities Tacobell may know about, your client's links will still work, and you won't even lose ground with the search engines.  There does seem to be an issue regarding whether you get a true 301 permanent redirect, or a 302 temporary redirect, so it would be good to double check the headers once you get it set up if you choose to do it this way.
0
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
LVL 21

Expert Comment

by:pinaldave
ID: 11811554
Hi 8riaN,
good one :-)

Regards,
---Pinal
0
 

Expert Comment

by:momentuminfotech
ID: 13650871
Hi,

I'm trying to find out what the most efficient way is to redirect to pages in this scenario:

The client want to display user friendly URLs like:

http://www.mywebsite.com/city/state/country/mypage.cfm

without creating the directories on server in actual .

I really don't want to just add a meta or javascript redirect or install any IIS extension, and was wondering if anyone knows of a script that could possibly reside in the application.cfm or application.cfc file . I dont want to put a redirect in a custom 404 error file on IIS.  

Does that make sense?  If so, can anyone offer a suggestion?
0
 
LVL 17

Expert Comment

by:Tacobell777
ID: 13651123
you can create virtual directories within the website
0
 
LVL 5

Expert Comment

by:8riaN
ID: 13653230
There are only a few choices I'm aware of:

1) a URL rewriting extension (best solution) like this: http://www.seoconsultants.com/windows/isapi/ or this: http://www.smalig.com/url_rewrite-en.htm
But you said no extensions.

2) Tacobell's virtual directory suggestion.  In that case the IIS Admin must set up a virtual directory for every state and county which points to somewhere.

3) A custom 404 page.

In the case of 2 or 3 above, you then would parse the Incoming URL to decide what to do next.

But shouldn't this be a new question?
8riaN
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A web service (http://en.wikipedia.org/wiki/Web_service) is a software related technology that facilitates machine-to-machine interaction over a network. This article helps beginners in creating and consuming a web service using the ColdFusion Ma…
If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question