?
Solved

Cold Fusion Redirect Script

Posted on 2008-02-08
7
Medium Priority
?
684 Views
Last Modified: 2013-12-24
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.
0
Comment
Question by:styleteks
  • 4
  • 3
7 Comments
 
LVL 36

Expert Comment

by:SidFishes
ID: 20854355
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
 

Author Comment

by:styleteks
ID: 20854719
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
 
LVL 36

Expert Comment

by:SidFishes
ID: 20867398
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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

Author Comment

by:styleteks
ID: 20867984
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
 
LVL 36

Expert Comment

by:SidFishes
ID: 20912394
did this work for you??
0
 

Author Comment

by:styleteks
ID: 20930517
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
 
LVL 36

Accepted Solution

by:
SidFishes earned 1500 total points
ID: 20932016
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

Featured Post

[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This guide will walk you through the essential considerations and tech stack for building scalable websites. Know how to grow your business the smart way!
This installment of Make It Better gives Media Temple customers the latest news, plugins, and tutorials to make their Grid shared hosting experience that much smoother.
The purpose of this video is to demonstrate how to automatically show related posts at the bottom of a blog post in WordPress. This will be demonstrated using a Windows 8 PC. Plugin “Yet Another Related Posts Plugin” will be used. Go to your…
The purpose of this video is to demonstrate how to insert an Iframe into WordPress. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php : Open Page or Post…
Suggested Courses

601 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question