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.
styleteksAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

SidFishesCommented:
are you not using the the full url???

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

maybe I'm not understanding

0
styleteksAuthor Commented:
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.
0
SidFishesCommented:
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

0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

styleteksAuthor Commented:
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.
0
SidFishesCommented:
did this work for you??
0
styleteksAuthor Commented:
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.
0
SidFishesCommented:
using this

http://www.bennadel.com/blog/378-Getting-The-Requested-URL-From-The-Page-Request-Object-Servlet-Without-Using-CGI.htm

with my code works

 
<cfoutput>
 
     <!--- Get request from ColdFusion page contenxt. --->
     <cfset objRequest = GetPageContext().GetRequest() />
      
     <!--- Get requested URL from request object. --->
    <cfset vUrl = objRequest.GetRequestUrl().Append(
    "?" & objRequest.GetQueryString()
     ).ToString()
     /> 
 
 
Old Url:   #vUrl#<br> 
 
<!--- get http:// or https:// and store it --->
<cfset vSlash = findnocase("/", vUrl)>
<cfset vMode = left(vUrl, vSlash+1)>
 
<!--- remove the mode so we can find the first / --->  
<cfset vUrl = replace(vUrl, "http://", "", "all")>
 
<!--- find the first / --->
<cfset vSlash = findnocase("/", vUrl)>
<!--- split the string --->
<cfset vLeft = left(vUrl, vSlash)>
<cfset vright = right(vUrl, len(vUrl)-vSlash)>
<!--- set new directory value --->
<cfset vRedir = "home/">
<!--- put string back together --->
<cfset vNewUrl = #vLeft# & #vRedir# & #vRight#>
                              
New Url:   #vmode##vNewUrl#                               
                                
</cfoutput>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Servers

From novice to tech pro — start learning today.