Skip to main content
Inspiring
March 6, 2014
Question

CFLOCATION question

  • March 6, 2014
  • 1 reply
  • 924 views

I have urls that have been changed and I need to relocate users to the new url.

I have been using this code.

  <cfif PATH_TRANSLATED CONTAINS "C:\inetpub\websites\mywebsite\abc\">

<cflocation url="http://www.mywebsite.com/newsite/abc/#pagename#">

</cfif>

This code works but anytime I add a new page to newsite I also need to add a copy of the page to the old site or a get a 404 error.

Is there a way I can say if a user comes to my site to this url  http://www.mysite.com/abc/thispage.cfm that they can be automatically redirected to

http://www.mysite.com/newsite/abc/thispage.cfm?

Basically redirect to the pagename in the new directory without having the page at the old location also.

This topic has been closed for replies.

1 reply

Participating Frequently
March 7, 2014

You want to do this at the webserver level, not anything to do with ColdFusion.  Look into URL rewriting via the likes of mod_rewrite, ISAPI_Rewrite or IIS URL Rewrite

weezerboyAuthor
Inspiring
March 7, 2014

So Ive got this and getting errors. What am I doing wrong?

<rewrite>

    <rules>

        <rule name="Redirect domain.com to jones" patternSyntax="Wildcard" stopProcessing="true">

            <match url="*" />

            <conditions>

                <add input="{HTTP_HOST}" pattern="http://www.mysite.com.com/jones/" />

            </conditions>

            <action type="Redirect" url="http://www.mysite.com/newsites/jones/{R:0}" />

        </rule>

    </rules>

</rewrite>

I just wan to redirect anyone trying to access any page at http://www.mysite.com.com/jones/ to http://www.mysite.com/newsites/jones/

Anit_Kumar
Inspiring
March 13, 2014

You can use the below code as your 404 page:-


<cfcontent reset="yes" />
<cfheader statuscode="301" statustext="Moved Permanently" />
<cfheader name="Location" value="http://www.mysite.com/newsites/jones/" />

Query string: "<cfoutput>#cgi.query_string#</cfoutput>"
<!--- <cfheader name="X-Content-Length" value="#getPageContext().getCFOutput().getBuffer().size()#"> --->

Regards,

Anit Kumar