4 Replies - 4332 Views - Last Post: 29 March 2012 - 08:35 AM Rate Topic: -----

#1 Shalinko  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 28-March 12

redirect according to url address

Posted 28 March 2012 - 03:27 AM

Hi, I have two domain names pointing to the same hosting account. Is it possible to redirect the user to a folder/page according to the url used?
e.g. user types 'www.site-a.com' I want to redirect to page 'site-a.cfm'....if 'www.site-b.com' redirect to 'site-b.cfm'

I have tried...

<!--- Get request from ColdFusion page contenxt. --->
<cfset objRequest = GetPageContext().GetRequest() />
 
<!--- Get requested URL from request object. --->
<cfset strUrl = objRequest.GetRequestUrl().Append(
"?" & objRequest.GetQueryString()
).ToString()
/>

<cfif #strUrl# EQ "http://www.vmedia.cz">
  <cfheader name="Location" value="http://www.quackit.com/coldfusion/tutorial">
<cfabort>
</cfif>



but it doesn't redirect.

Any help appreciated, many thanks.

Is This A Good Question/Topic? 0
  • +

Replies To: redirect according to url address

#2 Craig328  Icon User is offline

  • I make this look good
  • member icon

Reputation: 1926
  • View blog
  • Posts: 3,471
  • Joined: 13-January 08

Re: redirect according to url address

Posted 28 March 2012 - 06:26 AM

Welcome to DIC Shalinko!

I copied and pasted your code into a test page on my CF9 server and immediately saw the problem. Writing CF requires developing a debugging habit. In the case of your issue, you say the code never redirects so my first question was "why does line 10 (in your code) not work"? So, what I did was this:
<!--- Get request from ColdFusion page contenxt. --->
<cfset objRequest = GetPageContext().GetRequest() />
 
<!--- Get requested URL from request object. --->
<cfset strUrl = objRequest.GetRequestUrl().Append("?" & objRequest.GetQueryString()).ToString()/>

<cfoutput>strUrl: [#strUrl#]</cfoutput><cfabort>


If you copy/paste/run that, I think you'll see fairly quickly why the CFIF EQ is failing for you.

Good luck!
Was This Post Helpful? 0
  • +
  • -

#3 Shalinko  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 28-March 12

Re: redirect according to url address

Posted 28 March 2012 - 10:52 PM

Thanks Craig, glad I stumbled accross this site! I know what you mean about debugging, but how do I get my hosting company to Enable Robust Exception Information? I use debugging locally and normally solve the problem, but I have to run this code on the remote site because of the URL address.
It kind of works, but for some reason appends the original URL in front of the desired redirect, like so

"http://www.vmedia.cz/www.google.com" and then I just get a basic 404 saying I should enable robust.....

This is my code now:
<!--- Get request from ColdFusion page contenxt. --->
<cfset objRequest = GetPageContext().GetRequest() />
<!--- Get requested URL from request object. --->
<cfset strUrl = objRequest.GetRequestUrl().Append("?" & objRequest.GetQueryString()).ToString()/>

<cfif #strUrl# EQ "http://www.vmedia.cz/index.cfm?">
<cfheader statuscode="301" statustext="Moved Permanently">
<cfheader name="Location" value="www.google.com">
<cfabort>
</cfif>


I also tried using cflocation, but got the same result?
Was This Post Helpful? 0
  • +
  • -

#4 Craig328  Icon User is offline

  • I make this look good
  • member icon

Reputation: 1926
  • View blog
  • Posts: 3,471
  • Joined: 13-January 08

Re: redirect according to url address

Posted 29 March 2012 - 05:35 AM

For debugging...you could roll your own via the onerror method in Application.cfc to have it dump all the variables scopes you need for debugging (as well as the request and exception details).

For your redirect issue, I don't use CFHEADER much at all but I believe you need to prepend the "http://" to your URL. Try that and see what happens.
Was This Post Helpful? 1
  • +
  • -

#5 Shalinko  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 28-March 12

Re: redirect according to url address

Posted 29 March 2012 - 08:35 AM

View PostCraig328, on 29 March 2012 - 05:35 AM, said:

For debugging...you could roll your own via the onerror method in Application.cfc to have it dump all the variables scopes you need for debugging (as well as the request and exception details).

For your redirect issue, I don't use CFHEADER much at all but I believe you need to prepend the "http://" to your URL. Try that and see what happens.


Yes, of course, I didn't think of that! Anyway, I added "http://" to the URL and it did work, but in the meantime I found a way using
<CFSET CurrentURL = 'http://' & CGI.SERVER_NAME >

with
<cfif #CurrentURL# EQ "http://www.my-cv.cz">
<table width="300" border="0" align="center" cellpadding="0" cellspacing="0" style="margin-top:100px;">
  <tr>
    <td colspan="2"><img src="images/under-construction.gif" alt="Under construction" width="500" height="400"></td>
    </tr>
</table>

<cfabort>
<cfelseif #CurrentURL# EQ "http://www.vmedia.cz">
o l d  p a g e  h e r e
</cfif>



Which seems simpler to use, but in practical terms not sure of how easy to switch between both as it gets more complicated?
Thanks very much for the help, you can check it out at www.vmedia.cz and www.my-cv.cz if you like.
Thanks again....super site!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1