ses routes based on url?

Is there a way to have different ses routes depending on the baseurl?

not sure if this is the best way to handle this but I put simple IF statements in the Routes.cfm under config directory.

if(cgi.http_host eq ‘URL_NAME_HERE’){

setBaseURL(“http://URL_NAME_HERE/index.cfm”);
}


Jeremy R. DeYoung
Phone:615.261.8201

RantsFromAMadMan.com

If the two different domains used different ColdFusion applications, probably. routes.cfm is just a ColdFusion file, so you can put if statements and things in it, but it is only parsed once so whatever domain was used to init the framework would be the settings used.

Are you wanting to re-use the same code-base for two different apps, or have the same app accessible by two different URLs (and behave different based on that URL)?

~Brad

I’m not trying to change the baseUrl. I’m trying to add different routes. I tried a simple if then around my add route statements but I guess since the add route statements process when the coldbox loads it’s not behaving as expected.

<cfif cgi.HTTP_HOST eq “www.mydefaultdomain.com”>
one set of addRoute statements

some other set of addRoute Statements

I’m doing this because if the website has a custom url the first parameter in the list isn’t needed, I calculate it from the url.

For example:
www.mydefaultdomain.com/teamid/pageid

where as
www.mycustomdomain.com/pageid

I don’t need teamid because I have a function that looks up the teamid based on the custom domain name.

I have one other page that has some additional variables.

www.mydefaultdomain.com/teamid/pageid/month/year

www.mycustomdomain.com/pageid/month/year

Thanks for any help.

Can you just set up both set of routes and look up teamID based on URL when you can. If someone hits the default domain and there is no teamID passed in throw an error (or do whatever you want to deal with it). Depending on the position of the items in the route, you should be able to do optional items with the “?” I think.

Routes aren’t used to generate links so I assume the onus is on you to make sure you supply the teamID when using the default domain.

Thanks!

~Brad

Yes, you can do this.

Try setting routes with the addRoute method using a pattern like this:

addRoute(pattern=“domain1/route/here”,handler=“domain1”,action=“whatever”);
addRoute(pattern=“domain2/route/here”,handler=“domain2”,action=“whatever”);

Then, add a function called PathInfoProvider() to your routes.cfm file. You can read a little about the PathInfoProvider method here: http://wiki.coldbox.org/wiki/WhatsNew:3.0.0.cfm.

The PathInfoProvider method, if it exists, will be executed by the ColdBox SES Interceptor to get the CGI.PATH_INFO used to match routes. Using this function, you can inspect the host name and return a modified path_info value that will only match based on the proper domain.

Example:

function PathInfoProvider(Event){
var rc = Event.getCollection();
var prc = Event.getCollection(private=true);
// … stuff here …
switch(CGI.HTTP_HOST)
{
case ‘domain1’ :
return ‘/domain1#cgi.path_info#’;
break;

// … stuff here …

default:
// … stuff here …
break;

}
}

Aaron,

Thank you very much. This is exactly what I needed. If I get a chance to meet you at a CF event, dinner and beers on me. Thanks.

Jonathan