Link to home
Start Free TrialLog in
Avatar of styleteks
styleteks

asked on

Cold Fusion Redirect Script

I'm looking to perform a redirect that can accommodate file names in the originating link.  The issue is I've relocated a domain onto a shared server and created a sub-web, however, the host has no ability to setup the domain to point to the sub web folder.

For instance, let's say I have a domain called domain.com, and I want to point this to a folder called "Home".  So, I use one of the common redirect scripts for CF as follows:

<cfif cgi.server_name IS "domain.com">
  <cflocation url="home" addtoken="no">
</cfif>

OR, I USE...

<cfswitch expression="#cgi.server_name#">
  <cfcase value="domain.com">
    <cflocation url="home" addtoken="no">
  </cfcase>
</cfswitch>

However, the issue arises when I have referrer links across the internet that point to a specific page on that domain.  So, let's say your site has a link to point to www.domain.com/thispage.cfm.  Now, this link is broken, since CF does not seem to forward to www.domain.com/home/thispage.cfm

Is there any hope I am missing something here, and this can be corrected with some relatively simple code?  I really do not wish to move this site again.
Avatar of SidFishes
SidFishes
Flag of Canada image

are you not using the the full url???

<cflocation url="http://www.domain.com/home/thispage.cfm" addtoken="no">

maybe I'm not understanding

Avatar of styleteks
styleteks

ASKER

No, not in the cflocation tag.  I only use the directory "home".

However, it would be almost impossible to obtain every referring URL that points to a specific page and include that in the redirect script.  I was hoping there may be a way always take any traffic to the domain name and foward it to he directory while keeping the page name intact and not explicitly stating the page name in a cflocation tag.

I.E.
domain.com/thispage.cfm
always redirects to
domain.com/home/thispage.cfm

domain.com/thatpage.cfm
always redirects to
domain.com/home/thatpage.cfm

I hope this makes sense.
you could probably try something like this to build a different url string


<cfoutput>
 
 
<cfset vUrl = "www.domain.com/index.cfm">
 
#vUrl#<br>
 
<cfset vSlash = findnocase("/", vUrl)>
<cfset vLeft = left(vUrl, vSlash)>
<cfset vright = right(vUrl, len(vUrl)-vSlash)>
<cfset vRedir = "home/">
<cfset vNewUrl = #vLeft# & #vRedir# & #vRight#>
				
#vNewUrl#				
			
				
</cfoutput>

Open in new window

Sidfishes...

This looks exactly like what I need.  Do you see any draw backs using this approach?

I will test this today and accept the solution if all is well.

Thank you very much for the insight and response.
did this work for you??
SidFishes...

I've been testing the code you provide me to fit my needs however, I am running into an issue.

How do I set vURL to be the actual page the user is attempting to access?  I.E. The link on google is http://www.domain.com/page.cfm?theid=100

I would like the new virtual url to be www.domain.com/home/page.cfm?theid=100

I understand what you are doing in the above code, but it appears that I missing the way to capture the original url they user enters into the address field of the browser.  Is this possible?  I've searched through cgi variables and cannot seem to locate a solution.

Thanks again.
ASKER CERTIFIED SOLUTION
Avatar of SidFishes
SidFishes
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial