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.
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
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/
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
Copy link to clipboard
Copied
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.