Skip to main content
New Participant
April 23, 2015
Answered

Redirecting index.cfm to dynamic.cfm without parameters :(

  • April 23, 2015
  • 1 reply
  • 665 views

Hello Everyone, I have this code that works great, but there is one little problem.

When user inputs index.cfm it does not forward to plain dynamic.cfm

So it seems to me that i need to modify this code so it can handle at least one more option

The script works very well when user inputs index.cfm?myID=#url.myID then redirects to dynamic.cfm?myID=#url.myID

How could I make it work? Any help greatly appreciated

<!-- File name: index.cfm -->

<cfoutput>

<cfif isDefined("url.myID") AND IsNumeric(url.myID) AND url.myID NEQ 0>    

<cfheader statuscode="301" statustext="Moved Permanently">    

<cfheader name="Location" value="dynamic.cfm?myID=#url.myID#">

</cfif>

</cfoutput>

<cfabort>

    This topic has been closed for replies.
    Correct answer haxtbh

    You will need to add an "else" clause to your "if" statement. All you are doing is checking for the "myID" parameter and doing nothing if it doesnt exist.

    I assume you wont something like this:

    <cfoutput>

        <cfheader statuscode="301" statustext="Moved Permanently">

        <cfif isDefined("url.myID") AND IsNumeric(url.myID) AND url.myID NEQ 0>     

              <cfheader name="Location" value="dynamic.cfm?myID=#url.myID#">

        <cfelse>

              <cfheader name="Location" value="dynamic.cfm">

        </cfif>

    </cfoutput>

    <cfabort>

    1 reply

    haxtbhCorrect answer
    Inspiring
    April 24, 2015

    You will need to add an "else" clause to your "if" statement. All you are doing is checking for the "myID" parameter and doing nothing if it doesnt exist.

    I assume you wont something like this:

    <cfoutput>

        <cfheader statuscode="301" statustext="Moved Permanently">

        <cfif isDefined("url.myID") AND IsNumeric(url.myID) AND url.myID NEQ 0>     

              <cfheader name="Location" value="dynamic.cfm?myID=#url.myID#">

        <cfelse>

              <cfheader name="Location" value="dynamic.cfm">

        </cfif>

    </cfoutput>

    <cfabort>

    New Participant
    April 24, 2015

    Hello Haxtbh, Yes it does work thank you so much