Skip to main content
September 12, 2014
Answered

How to redirect on htttp to https with www redirect of coldfusion mx7?

  • September 12, 2014
  • 12 replies
  • 10880 views

Hi any one help me  - How to redirect on htttp to https with www redirect of coldfusion mx7?

    This topic is closed to new replies. Start a new post to keep the conversation going.
    Correct answer

    You should run the following code, and convince yourself that the URLs are accessible, by opening each in a browser:

    <cfoutput>

    https://www.site.com#CGI.SCRIPT_NAME# <br>

    https://#CGI.SERVER_NAME##CGI.SCRIPT_NAME# <br>

    http://www.site.com#CGI.SCRIPT_NAME#

    </cfoutput>


    I used below code. its working perfectly. thanks a lot. 

    <cfif (CGI.SERVER_NAME EQ "site.com") and (CGI.https NEQ "on")>

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

    <cfheader name="Location" value="https://www.site.com#CGI.SCRIPT_NAME#">

    </cfif>

    <cfif (CGI.SERVER_NAME EQ "www.site.com") and (CGI.https NEQ "on")>

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

    <cfheader name="Location" value="https://www.site.com#CGI.SCRIPT_NAME#">

    </cfif>

    <cfif CGI.SERVER_NAME EQ "site.com">

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

    <cfheader name="Location" value="http://www.site.com#CGI.SCRIPT_NAME#">

    </cfif>

    12 replies

    BKBK
    Community Expert
    Community Expert
    September 12, 2014

    To redirect as you describe is a matter for the web server. The settings will therefore depend on whether you use Apache, IIS or Coldfusion's built-in JRun.

    September 12, 2014

    Thanks...

    below code i have used but it returns status is 302 redirect. need code for 301 redirect?

    <cfif (CGI.SERVER_NAME EQ "site.com") and (CGI.https NEQ "on")>

    <cflocation addtoken="no" url="https://www.site.com#CGI.SCRIPT_NAME#">

    </cfif>

    <cfif (CGI.SERVER_NAME EQ "www.site.com") and (CGI.https NEQ "on")>

    <cflocation addtoken="no" url="https://#CGI.SERVER_NAME##CGI.SCRIPT_NAME#">

    </cfif>

    <cfif CGI.SERVER_NAME EQ "site.com">

        <cflocation addtoken="no" url="http://www.site.com#CGI.SCRIPT_NAME#">

    </cfif>

    BKBK
    Community Expert
    Community Expert
    September 12, 2014

    In pre-Coldfusion 8, you could use the combination

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

    <cfheader name="Location" value="https://www.site.com#CGI.SCRIPT_NAME#">

    in place of

    <cflocation addtoken="no" url="https://www.site.com#CGI.SCRIPT_NAME#">