• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

CFLOCATION question

Participant ,
Mar 06, 2014 Mar 06, 2014

Copy link to clipboard

Copied

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.

Views

777

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Mar 07, 2014 Mar 07, 2014

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Mar 07, 2014 Mar 07, 2014

Copy link to clipboard

Copied

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/

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Employee ,
Mar 12, 2014 Mar 12, 2014

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 13, 2014 Mar 13, 2014

Copy link to clipboard

Copied

LATEST

weezerboy wrote:

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/

The main URL remains the same, so isn't <match url="*" /> too general? Couldn't you use something much simpler like this:

<rewrite>

    <rules>

        <rule name="Rewrite to new version of page">

            <match url="http://www.mysite.com/([0-9a-z]+)/([0-9a-z\.]*)" />

            <action type="Rewrite" url="http://www.mysite.com/newsites/{R:1}/{R:2}" />

        </rule>

    </rules>

</rewrite>

I have assumed '.com.com' is a typo.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation