17 Replies Latest reply on Jun 19, 2006 1:21 PM by tinu8805

    Redirecting pages

      Not being a programmer at all (having adopted the company site from a former employee) - I wing it and ask for help when I'm stuck. I don't know why my code isn't working. I have two issues.

      Issue 1:
      I'll explain a little so you understandhow our site is set up and works (maybe it will be obvious to you, but it wasn't to me), and what I needed done and how I got it to do it. Then I'll explain my problems.

      Our site is set up so that everything displays off the index page, all links to internal pages would have a path like this:
      www.mysite.com/index.cfm?action=pagename All the internal pages are stored off the root folder in a subfolder called includes.

      What I needed done:
      Telling an end user to type inwww.mysite.com/index.cfm?action=help was asking for trouble, so I wanted them to be able to enter www.mysite.com/help and have the help page load.

      How it got done
      I created a subfolder named help, off my root.
      In that subfolder is an index.cfm.
      The ONLY code in that index page is <cflocation url="index.cfm?action=page">

      Thus, when someone types www.mysite.com/help, the index page from the help folder redirects them to the help.cfm page (which is stored in the previously mentioned folder called includes)

      Does that make sense?

      Well it works for two of my pages (www.mysite.com/help and www.mysite.com/other)

      Now here is the problem
      When I start navigating the path file deeper, with subfolders, it doesn't work. - which is why I'm here.

      If you understand what I did to fix redirect, hopefully you can help me redirect some more pages.

      I need the following paths to work:

      www.mysite.com/ subfolder/help - needs to display the help.cfm file which is stored in my 'includes' folder
      www.mysite.com/ subfolder/faq - needs to display the faq.cfm file which is stored in my 'includes' folder
      www.mysite.com/ subfolder/updates - needs to display the updates.cfm file which is stored in my 'includes' folder

      I think the 'subfolder' is what is causing my problem.

      Inside the subfolder, I have 3 folders, help, faq and updates.
      Inside each of those folders I have an index.cfm file, with only the code:
      <cflocation url="index.cfm?action=page"> where page directs to the help, faq and updates.cfm respectively.

      The actual help.cfm, faq.cfm and updates.cfm are located in the 'includes' folder with all the rest of the pages in my site.

      In the 'index.cfm' page that controls my site, I'm guessing the code to direct to the pages in a sub folder..

      In abbreviated format, this is the code that I have on my master index.cfm page:

      <cfcase value ="faq">
      <cfinclude template="includes/faq.cfm">

      Is it somewhere in the cfcase value where I'm going to make an edit?

      When I had the faq file stored in the subfolder, my cfcase looked like this (and didn't work):

      <cfcase value ="faq">
      <cfinclude template=" subfolder/faq.cfm">

      Issue 2:
      Now after all THAT ... it doesn't work in Firefox. I get a firefox message
      "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."

      Can anyone suggest code that will work with Firefox AND IE?

      Thank You.
        • 1. Re: Redirecting pages
          SafariTECH Level 1
          The primary issue I think you are running into, is that you are making this overly complicated and tough to manage.

          www.mysite.com/subfolder/help = a directory structure.

          To begin with, in this scenario, you are going to need new sub directories for everything you add to the site, which can get really tedious.

          The second thing is that the " includes" folder is a sub directory of the root:
          <site root>/includes

          When you go to a directory structure such as:
          that is really located:
          <site root>/subfolder/help

          The page in the " help" folder would have to refer back 2 directories and then forward 1 into the " includes" folder to find the file. Your current coding does not seem to be doing that. The way they are right now, ( in the initial example) they are trying to load the file from " includes" as a sub directory of the " help" directory, which doesn't actually exist.

          In the example using index.cfm?page=pagename, when it is located in the index page that is within that same folder, it is referring to itself and that is why FF ( and I'm surprised not others) are entering into a recurring loop.

          If you really, really, really need to stick with this structure and concept, you can use the following code for redirection, and it should work in every sub directory no matter how deep you go ( so long as all the inclusion files are in the " includes" directory and you do not use it in the root index file).

          <CFLOCATION addtoken="No" url="/index.cfm?page=pagename">

          By using a slash at the beginning of the path, you are telling it to always start at the root location of the site to find the index file, no matter where the request initiates from.

          Ultimately it would be better ( and easier to manage) if you don't require all the subdirectories.
          • 2. Redirecting pages
            L1FEisG00D Level 1
            Thank you for the feedback. I agree this directory structure is dificult to work with.

            I have added many pages to the site and not had to deal with creating subfolders and working with the directory. I've been able to add the pages, reference them in the root index page, and create links to those pages from within the site itself. They work equally well in IE or FF

            This directory sturcture only just became an issue when sofware associated with our site was written directing "FAQ" to the www.mysite.com/subfolder/faq... Since this is hard coded and I can't change it, I do have to work with it. This path HAS to work. If it were a matter of creating a hyperlink to a page, the index.cfm?action=page would work fine.

            I edited my code at your suggestion to: <CFLOCATION addtoken="no" url="index.cfm?action=faq"> - saved - uploded. Now it doesn't hang endlessly -but it doesn't show the faq page either.

            It shows the root index page, but not the content of the faq page. This leads me to think that now I have an issue with the code on my root index.

            This is what I have now:
            <cfcase value="subfolder/faq">
            <cfinclude template="/includes/faq.cfm">

            Do I need to change the CFCASE VALUE?
            I tried changing it to <cfcase value="/subfolder/faq"> (adding the slash before the subfolder) and it didn't change anything.

            When I try to go to the www.mysite.com/subfolder/faq, this is the url in the address bar displays:
            so it appears to go to the right place, but the text that I have on the faq.cfm is not what shows in the browser window.

            I'm editing in Dreamweaver MX ... and now some of the code is coming up highlighted as invalid code.
            Of the following code, the underlined text is coming up highlighted as invalid:
            <cfcase value="subfolder/faq">
            <cfinclude template="includes/faq.cfm">
            This is making me crazy.

            FF is another issue all together that I'll deal with after this all gets worked out. it is fine with the www.mysite.com/index.cfm?action=pagename hyperlinks that I have. But as you mentioned, it is stuck in an endless loop when trying to load my /help page that has the <CFLOCATION url=">
            • 3. Re: Redirecting pages
              First, you said you updated your code to:

              <CFLOCATION addtoken="no" url="index.cfm?action=faq">

              But this still shouldn't work and is not the code offered by SafariTECH. Either you mistyped it here, or you are indeed still using code that won't work.

              What you need to do is use a root relative link in the URL attribute of the CFLOCATION tag This requires the forward slash character "/" in front of index.cfm, so the tag looks like

              <CFLOCATION addtoken="no" url="/index.cfm?action=faq">

              That way, no matter what level of URL subdirectory your browser is pointed to, it will always find the mysite.com/index.cfm because it looks at the root level.

              Second - I'm not clear on what is being accomplished in the SWITCH CASE you are using:

              <cfcase value="subfolder/faq">
              <cfinclude template="includes/faq.cfm">

              However it appears that the CASE in question is not being found true, and therefore not calling the faq.cfm content from the includes folder, and so the page just sits.

              Perhaps if you post the whole thing, including all between the open and close CFSWITCH, we can help. I am speculating but I suspect that the switch expression is looking at the URL variable. Therefore the case value will need to be the URL variable, not the URL path. If your code says

              <cfswitch expression="#URL.action#">

              then I am correct. In such case your code should read

              <cfcase value="faq">
              <cfinclude template="/includes/faq.cfm">
              • 4. Redirecting pages
                L1FEisG00D Level 1
                You're right, I had mistyped the code in my question - my page has the code as:
                <CFLOCATION addtoken="no" url="/index.cfm?action=faq">

                My understanding as to why the switch case is used, is that it directs what page.cfm displays as the contents in the index page.

                There is a <CFCASE VALUE=> </CFCASE> for each and every single page in my site. If the <CFCASE VALUE= >tags are not on the root index page (or they're spelled wrong), then the page will not display. What I get then is a blank root index page.

                Here's a sample of the switch case values.

                <cfswitch expression="#url.action#">

                <cfcase value="home">
                <cfinclude template="includes/home2.cfm">

                <cfcase value="shop">
                <cfinclude template="includes/shop.cfm">

                <cfcase value="subfolder/faq">
                <cfinclude template="/subfolder/faq.cfm">


                If I were to manually enter the url as www.mysite.com ... the home page displays.

                If I click on the 'shop' link (the link is on the index.cfm page, thus displays in every page in the site), the url in the address bar displays

                I can manually enter the url in for every page in the site. For example: substituting the action=contactus to display the contactus.cfm.

                Except for these pages that are in the subfolder directory. Those in the subfolder directory need to be able to be viewed by typing www.mysite.com/subfolder/faq into the address bar.

                The times that I've forgotten to enter the <CFCASE VALUE > on the root index page (or typoed), say for example for the help page, then the contents of the help page will not display.

                It is as if the browser requires the code to be in the index page for it to display.

                This is exactly what it looks like is happening.

                Now, for the 3rd (the bold one) ... I 'guessed' that I would need to include the directory path to the index page for the redirect to work. Thus, why I included the subfolder before the actual page name as

                <cfcase value=" subfolder/faq">
                <cfinclude template="/subfolder/faq.cfm">

                Maybe my guess is what is causing the problem. Maybe I can't direct that way. And if that is the case my question becomes

                How do I create the code so that someone can enter www.mysite.com/subfolder/faq as the address, and have the correct page display?

                I MUST have the path www.mysite.com/subfolder/faq display the faq.cfm page.

                I do appreciate the help you guys are giving me - I'm the first to admit I don't know the first thing about ColdFusion. As I first posted, I wing it. Oh, and for the record, the 'invalid code' highlights are no longer highlighted - and I didn't change a thing.
                • 5. Re: Redirecting pages
                  r-con Level 1
                  Thanks for the detail.

                  Simple answer:
                  You need to change

                  <cfcase value="subfolder/faq">
                  <cfinclude template="/subfolder/faq.cfm">


                  <cfcase value="faq">
                  <cfinclude template="/subfolder/faq.cfm">


                  Following your current scheme, this assumes that there are no other subfolders named faq. In other words, you will need to assign a unique value for the URL variable "action" in each redirect.

                  I'll try to describe how this simple application is working, so you can make the right decisions in the future to make sure it keeps working.

                  When you type the link or URL "www.mysite.com/index.cfm?action=shop", there are two pieces:
                  1) A URL - www.mysite.com/index.cfm
                  2) A URL Variable - ?action=shop

                  In other words, the URL variable is everything declared after the ?. It comprises the variable name, and the value of the variable.

                  In this case, the variable name is ACTION and the value is SHOP. Quite simply, action=shop.

                  This URL variable is passed in the URL, and is evaluated by code in your index.cfm as the basis for which page to display.

                  This is accomplished, as you guessed, in the SWITCH/CASE statement. In the code it is customary to include the scope of the variable (url), followed by a period (.), and the name of the variable. Variables are surrounded by hashes ##:


                  Suffice to say that there are other variable scopes but we won't get into that.

                  The CFSWITCH tag states which variable to look at. We want to evaluate the url variable "action", so we specify "#url.action#", as below:

                  <cfswitch expression="#url.action#">

                  The CFCASE tag provides each of the possible cases for URL variables: shop, faq, etc. It appears you have figured this out.

                  In explaining this, it should become apparent that each folder and subfolder you create must use a unique URL variable in order to assure that each page is correctly displayed. It doesn't even have to match the folder name - it's completely arbitrary, as long as it corresponds to the correct page in your CFCASE tag.

                  Hope that helps.
                  • 6. Redirecting pages
                    SafariTECH Level 1
                    Since the action in the URL is "faq", that is what you need a condition for in your CFSWITCH... also, your current switch is not looking for FAQ in the includes folder, which it should be

                    instead of :

                    <cfcase value="subfolder/faq">
                    <cfinclude template="/subfolder/faq.cfm">

                    try this:

                    <cfcase value="faq">
                    <cfinclude template="/includes/faq.cfm">

                    It doesn't matter where the request came from, so long as you have a condition that fulfills what the action in the URL needs, and it loads the proper page ... all of which are in the includes folder

                    EDIT: Sorry r-con, I didn't see your post when I made this, but I think we did the same thing pretty much

                    • 7. Re: Redirecting pages
                      SafariTECH Level 1
                      Once you get that running, unless you have some non-conforming pages that load during an action request, you really do not need that CFSWITCH block.

                      In other words, if all inclusion pages are found in the folder "includes", and all page names are the exact same as the action variable supplied to the index file, then all you really need is :

                      <CFIF IsDefined("url.action")>
                      <CFINCLUDE template="/includes/#url.action#.cfm">
                      <P>There was no template requested.</P>
                      [or show a default file here]

                      This is a simple example, but replaces a lot of CFSWITCH code.

                      • 8. Redirecting pages
                        L1FEisG00D Level 1

                        Originally posted by: SafariTECH
                        Since the action in the URL is "faq", that is what you need a condition for in your CFSWITCH... also, your current switch is not looking for FAQ in the includes folder, which it should be

                        instead of :

                        <cfcase value="subfolder/faq">
                        <cfinclude template="/subfolder/faq.cfm">

                        try this:

                        <cfcase value="faq">
                        <cfinclude template="/includes/faq.cfm">

                        It doesn't matter where the request came from, so long as you have a condition that fulfills what the action in the URL needs, and it loads the proper page ... all of which are in the includes folder

                        Yes, this is what r-con had said, but he added

                        Following your current scheme, this assumes that there are no other subfolders named faq. In other words, you will need to assign a unique value for the URL variable "action" in each redirect.

                        Which is what I would have brought back to the table, because I DO have another faq.cfm page. The page I've been referring to as faq.cfm, is actually named fbfaq.cfm ... and I have a faq.cfm.

                        In my case switching, this is what I already have for a different FAQ page:

                        <cfcase value="faq">
                        <cfinclude template="includes/faq.cfm">

                        It directs to the faq.cfm page stored in the includes folder.

                        In the same location, I have the one we've been working with, named fbfaq.cfm.

                        If I fix my code for the fbfaq.cfm to

                        <cfcase value="faq">
                        <cfinclude template="includes/fbfaq.cfm">

                        it will not know which case value to refer too.

                        ** Remember that I have a subfolder that contains the faq folder which contains the index.cfm who's only code is to redirect to the fbfaq.cfm file stored in the includes folder
                        <CFLOCATION addtoken="no" url="/index.cfm?action=fbfaq"> **

                        All this so the end user will be able to use a www.mysite.com/subfolder/faq link from within their program.

                        My thought would be to change the 'original' switch to something like

                        <cfcase value="faq2">
                        <cfinclude template="includes/faq.cfm">

                        and then go find/replace all link reference to (action=faq) to (action=faq2)

                        Once that is done, then I'd go ahead and get this original problem edited to be

                        <cfcase value="faq">
                        <cfinclude template="includes/fbfaq.cfm">

                        This would work, right?
                        • 9. Re: Redirecting pages
                          SafariTECH Level 1
                          yep - the way you are working the system, you need to have a unique action code for every different file in the includes folder, so that's how you'll have to do it.

                          ultimately, you could still get rid of the CFSWITCH if you use action=fbfaq and name the file fbfaq.cfm and then just use the simpler code I gave you ... but your way will still work.
                          • 10. Re: Redirecting pages
                            L1FEisG00D Level 1
                            I'm back ....

                            I got all this done:

                            1 - I did the find/replace for action=faq to action=faq2

                            2 - Then changed the case value for that specific page to:

                            <cfcase value="faq2">
                            <cfinclude template="includes/faq.cfm">

                            3 - Once that was done, then edited the original problem to:

                            <cfcase value="faq">
                            <cfinclude template="/includes/fbfaq.cfm">

                            The whole thought was that I'd be able to go to the browser and enter www.mysite.com/subfolder/faq and have it dislay the fbfaq.cfm page.

                            It doesn't. It still displays only the root index.cfm

                            I've checked the subfolder/faq/index.cfm and it has the <CFLOCATION addtoken="no" url="/index.cfm?action=fbfaq"> code to direct the browser to show the fbfaq.cfm page

                            Next thought?
                            • 11. Re: Redirecting pages
                              pete_freitag Adobe Community Professional
                              A few things.

                              1 - It's not a good idea to use CFLOCATION, as it is doing a temporary redirect. You should be doing a perminent redirect. See my blog entry about this

                              2 - You can pretty easily write some rules on the web server to do this using either mod_rewrite on apache, or other options for iis
                              • 12. Re: Redirecting pages
                                SafariTECH Level 1
                                He needs it to work this way ... it's just the way the project started long ago, and not everyone has access to the servers. We have already determined this is not an efficient structure for the site, but he is working with what he has. CFLOCATION is fine for this as it stands.

                                Back to L1FEisG00D :

                                If the subdirectory index file has the CFLOCATION code you posted, it should work ... however, you may be hitting a caching issue either browser-side, server-side, or proxy-side ( most ISPs use proxy caching even if you don't know it)

                                To do a quick verification, try setting the browser's cache settings to " every visit to page". If this fixes the problem, then that was the problem and we can show you some additions that can likely help evade the cache regardless of where it is resulting.
                                • 13. Re: Redirecting pages
                                  L1FEisG00D Level 1
                                  Okay, I reset my browser to ""every visit to page" and it still doesn't load.

                                  I wondered if maybe the problem might be in the actual fbfaq.cfm page itself?

                                  All the other pages I've put into my site, I've used an existing page as the template (save as another name and delete the content and add my own). For this page, I started with the Dreamweaver MX "file/New/ColdFusion page" method. There is code on this page that isn't on my other pages.
                                  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
                                  <html xmlns=" http://www.w3.org/1999/xhtml">
                                  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
                                  <title>Untitled Document</title>

                                  I plugged in some test text between the body tags.

                                  The page that I have directly off the www.mysite.com /folder ... loads and the test text I plugged in, displays.
                                  The pages off the directory www.mysite.com /folder/page ... do not display

                                  All the existing pages, the code starts right in with the html table code ...

                                  Since the /folder page will work with the default text in there, then I'm guessing that this isn't my problem.

                                  And since this 'redirect' is a perminant move, should I consider using the method as described by pete_freitag ? SEO is an issue, I don't want my site blackballed by Google for having so many redirects. I was just reading about that today. Also, when reading the blog, there was a question re FF not having an issue with the MOVED code.

                                  Once I get this all worked out, FF still isn't going to work to display my redirected pages.

                                  • 14. Re: Redirecting pages
                                    L1FEisG00D Level 1
                                    Ok, here is more information that might help someone diagnose what is going wrong with my site.

                                    - index.cfm (containing only the code <cflocation url="index.cfm?action=SubfileA"> (

                                    First, the path that works:

                                    Off my root, I have a subfolderA, in which is an index.cfm file
                                    that index.cfm file has ONLY this code: <cflocation url="index.cfm?action=pageA">

                                    • 15. Redirecting pages
                                      L1FEisG00D Level 1
                                      Ok, here is more information that might help someone diagnose what is going wrong with my site.

                                      -index.cfm has all the code to direct which page from the includes folder displays
                                      <cfinclude template="/includes/subfileA.cfm">
                                      <cfinclude template="/includes/fbhelp.cfm">
                                      <cfinclude template="/includes/fbfaq.cfm">
                                      <cfinclude template="/includes/update.cfm">

                                      Root/ SubfolderA
                                      - index.cfm (containing only the code <cflocation url="index.cfm?action=SubfileA">
                                      Root/SubfolderA Help
                                      - index.cfm (containing only the code <CFLOCATION addtoken="no" url="/index.cfm?action=fbhelp">
                                      Root/SubfolderA/ FAQ
                                      - index.cfm (containing only the code <CFLOCATION addtoken="no" url="/index.cfm?action=fbfaq">
                                      Root/SubfolderA/ Updates
                                      - index.cfm (containing only the code <CFLOCATION addtoken="no" url="/index.cfm?action=updates">
                                      Root/ includes
                                      - SubfileA.cfm
                                      - fbhelp.cfm
                                      - fbfaq.cfm
                                      - updates.cfm

                                      HERE IS THE NEW INFORMATION THAT I HOPE HELPS SOLVE THIS

                                      This works:
                                      You can enter www.mysite.com/subfolderA and it will redirect to display the subfileA.cfm

                                      The URL when the page works looks like this:

                                      This does not work
                                      You can not enter www.mysite.com/subfolderA/fbfaq and have it redirect to display the fbfaq.cfm

                                      The URL when the page doesn't work (and comes up blank) looks like this:

                                      Thanks to anyone who can figure out why my directory path files won't work.

                                      • 16. Re: Redirecting pages
                                        I have run into the same issue and have come up with a much simpler solution.

                                        Create a file called help.cfm
                                        In that file
                                        <cfset action="help">
                                        <cfinclude template="index.cfm">

                                        Then your URL would be http://www.yoursite.com/help.cfm

                                        • 17. Re: Redirecting pages
                                          If your company is using Apache as the webserver, your problem is easily solved by Apache's URL Rewriting module.

                                          Howerver, this is no longer dynamic ... the rewriting part can be manipulated if its in .htaccess and the server admin allowed it to overwrite.