Skip to main content
Participant
Apr 23, 2015 10:53 PM UTC
Answered

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

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 is closed to new replies. Start a new post to keep the conversation going.
    haxtbhCorrect answer
    Inspiring
    Apr 24, 2015 8:20 AM UTC

    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>

    2 replies

    haxtbhCorrect answer
    Inspiring
    Apr 24, 2015 8:20 AM UTC

    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>

    Translate
    Participant
    Apr 24, 2015 4:04 PM UTC

    Hello Haxtbh, Yes it does work thank you so much

    Translate