How to enable URL rewriting in cfwheels 1.4 on iis 7.5?

87 views
Skip to first unread message

Thorsten Eilers

unread,
Jun 19, 2015, 10:53:05 AM6/19/15
to cfwh...@googlegroups.com
Hi,
I read almost every thread on various forum about this issue and tried a lot of settings, but have hat no success until now.
I posted the queston in stackoverflow, too. http://stackoverflow.com/questions/30920703/how-to-enable-url-rewriting-in-cfwheels-1-4-on-iis-7-5

I use cfwheels 1.4 on Railo 4.2.2.004 on windows server 2008R2 with IIS 7.5 and can't get URL rewriting to work.

In config/settings.cfm I have

set(URLRewriting="On");

My web.config looks like this

    <?xml version="1.0" encoding="UTF-8"?>
    <configuration>
        <system.webServer>
            <rewrite>
                <rules>
                        <rule name="ColdFusion on Wheels URL Rewriting" enabled="true">
                            <match url="^(.*)$" ignoreCase="true" />
                            <conditions logicalGrouping="MatchAll">
                                <add input="{SCRIPT_NAME}" matchType="Pattern" ignoreCase="true" negate="true" pattern="^/(flex2gateway|jrunscripts|cfide|CFFileServlet|cfformgateway|railo-context|files|images|javascripts|miscellaneous|stylesheets|robots.txt|favicon.ico|sitemap.xml|rewrite.cfm)($|/.*$)" />
                            </conditions>
                            <action type="Rewrite" url="/rewrite.cfm/{R:1}" />
                        </rule>
                </rules>
            </rewrite>
        </system.webServer>
</configuration>

I installed the URL rewrite module in IIS. IIS does show the inbound rules out of the web.config file.

The browser shows an

Error: Redirection error

I basically followed: http://stackoverflow.com/questions/20227106/removing-index-cfm-from-url-with-web-config


What am I missing? 


If I use the Test Pattern Tool in IIS, what should the Input data to test look like?

www.mydomain.com/index.cfm/images/home

or

www.mydomain.com/images/home


What should the result be?

www.mydomain.com/index.cfm/images/home

or

www.mydomain.com/images/home



Regards Thorsten


Thorsten Eilers

unread,
Jun 20, 2015, 6:55:22 AM6/20/15
to cfwh...@googlegroups.com
Hi, by further investigatin the issue I guess the problem lies in my code, not in the rewriting rules.

This is what I have. I guess the redirectTo(controller="#request.domaininfo.getHomeController()#", action="#request.domaininfo.getHomeAction()#"); leads to the issue.

events/onrequeststart.cfm
request.domaininfo = $createObjectFromRoot(path="lib", fileName="Domain", method="init", scope=duplicate(cgi));

controllers/SetControllerAndView.cfc
public void function setControllerAndView() {
    redirectTo(    controller="#request.domaininfo.getHomeController()#",
                       action="#request.domaininfo.getHomeAction()#");
}

lib/domain.cfc
<cfcomponent output="false">
<cfinclude template="../wheels/global/functions.cfm">

<cfset variables.domain = {}>

    <cffunction name="init">
        <cfargument name="scope" type="struct" required="true">
       
        <cfset var loc = {}>       
        <cfif !StructKeyExists(scope, "SERVER_NAME") OR !len(scope.SERVER_NAME)>
            <cfthrow type="Domain.ServerName" message="cannot determine server name. make sure server_name key is present and not blank">
        </cfif>
       
        <cfset loc.domain = scope.server_name>       
        <cfif left( loc.domain, 4 ) EQ 'www.'>
            <cfset loc.domain = mid( loc.domain, 5 )>
        </cfif>
       
        <cfset variables.domain = _getDomainInformationFromDatabase(loc.domain)>
       
        <cfreturn this>
    </cffunction>

<cffunction name="_getDomainInformationFromDatabase" access="private" returntype="struct">
        <cfargument name="domain" type="string" required="true">
       
        <cfset var loc = {}>
        <cfset loc.findDomain = model("Domain").findOne(where="domain='#arguments.domain#'")>
       <cfif !IsObject(loc.findDomain)>
            <cfthrow type="Domain.NotFound" message="cannot find a record for #arguments.domain# in the database">
        </cfif>
        <cfset variables.domain = loc.findDomain.properties()>
        <cfreturn variables.domain>
 </cffunction>
<cffunction name="getDomain">
     <cfreturn variables.domain.domain>
</cffunction>
<cffunction name="getHomeController">
     <cfreturn variables.domain.homecontroller>
 </cffunction>
 <cffunction name="getHomeAction">
     <cfreturn variables.domain.homeaction>
 </cffunction>
</cfcomponent>

Does anybody has a hint how to solve this?
Regards
Thorsten

Thorsten Eilers

unread,
Jun 20, 2015, 7:23:13 AM6/20/15
to cfwh...@googlegroups.com
Not to forget:

config/routes.cfm

addRoute(name="home", pattern="", controller="SetControllerAndView", action="setControllerAndView");


Thorsten Eilers

unread,
Jun 20, 2015, 7:35:04 AM6/20/15
to cfwh...@googlegroups.com
If redirectTo() is the problem, is there a way to call the action in a controller directly from SetControllerAndView?
Or could in config/routes.cfm the route parameters be dynamically evaluated?
addRoute(name="home", pattern="", controller="#DynamicSetControllerAndView#", action="#DynamicSetControllerAndView#");

Or any other solution?


Andy Bellenie

unread,
Jun 20, 2015, 9:48:43 AM6/20/15
to cfwh...@googlegroups.com
Not sure if this helps but I've fixed some weird rewriting issues on iis by replacing SCRIPT_NAME with PATH_INFO in the web.config file rule

Sent from my iPhone
--
You received this message because you are subscribed to the Google Groups "CFWheels" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cfwheels+u...@googlegroups.com.
To post to this group, send email to cfwh...@googlegroups.com.
Visit this group at http://groups.google.com/group/cfwheels.
For more options, visit https://groups.google.com/d/optout.

Thorsten Eilers

unread,
Jun 20, 2015, 10:16:20 AM6/20/15
to cfwh...@googlegroups.com
Hi Andy, tried it, but same error. But thanks anyway. I guess my code is too complex. Have to simplify it a little bit.

Thorsten Eilers

unread,
Jun 24, 2015, 1:00:47 PM6/24/15
to cfwh...@googlegroups.com
FYI
I solved the problem by replacing redirectTo() with the plugin internalredirect. ;-)

public void function setControllerAndView() {                   
     
        /*redirectTo(    controller="#request.domaininfo.getHomeController()#",
                    action="#request.domaininfo.getHomeAction()#");*/
                   
        // use plugin internalredirect.cfc
        internalredirect(    controller="#request.domaininfo.getHomeController()#",
                            action="#request.domaininfo.getHomeAction()#");       
    }

Thorsten Eilers

unread,
Jun 24, 2015, 1:18:03 PM6/24/15
to cfwh...@googlegroups.com
Back to start! After a restat it throws an error!

"Multiple redirects happening. Fix your code!"

Dissapointing!
Reply all
Reply to author
Forward
0 new messages