views:

315

answers:

4
+1  Q: 

301 Redirect

Hi all, i need to rediret my site from say http://www.foo.com/index.cfm to http://www.foo.com. In this application index.cfm is my default page that i have made in IIS. When i am trying 301 redirect i am getting redirect loop error. Whole app is in coldfusion. i am doing this setting in iis on my index.cfm page. Please give some advice on this. Thanks in adv.

A: 

Well I don't know coldfusion but you may condition the 301 header output just if the URL used to access the script index.cfm has any character extra on it (just if the request method is GET), this way you'll avoid infinite redirects. Here some pseudocode to explain myself:

if URL is not 'http://www.foo.com' and method is 'GET'
    output header '301 http://www.foo.com/'
victor hugo
+3  A: 

So in IIS your default page setup looks for index.cfm? I think you are getting the redirect loop because to the server http://www.foo.com/index.cfm is the same as http://www.foo.com.

It sounds like you are wanting to just hide the "index.cfm" from being displayed to the user?

In this case I don't think that trying to use a 301 redirect is the way to go.

You might want to take a look at IIS 7's URL rewrite feature, and look at Approach #3

Richard West
+2  A: 

You can get the full URL (i.e. with or without the index.cfm depending on what was actually requested) with getPageContact().getRequest().getRequestUrl() which returns a java.lang.StringBuffer

So, you can just do this:

<cfset FullUrl = getPageContext().getRequest().getRequestUrl().toString() />

<cfif FullUrl EQ 'http://www.foo.com/index.cfm'&gt;
    <cflocation url="http://www.foo.com/"/&gt;
</cfif>
Peter Boughton