URL rewriting on ColdFusion

Topics: Developer Forum
Jun 7, 2009 at 7:37 PM


On my website I have internal links like this one: http://www.website.com/temporary-contracts/contact which I redirect to the ColdFusion URL http://www.website.com/temporary_contracts/index.cfm?loc=contact&lng=EN&CFID=86356&CFTOKEN=76213163

Now I was wondering if it is possible to encode rewrite rules in IsapiRewrite4.ini which would still show http://www.website.com/temporary-contracts/contact in the address bar instead of this Search Engine UNfriendly URL ?

I don't have experience with this and in the example ini's, there is nothing that does this I guess...

Thanks in advance.


Jun 11, 2009 at 4:38 PM

Hi Pascal,

Hopefully this should be fairly straightforward.

Try using:

RewriteRule ^/temporary-contracts/contact/?$ /temporary_contracts/index.cfm?loc=contact&lng=EN&CFID=86356&CFTOKEN=76213163

Then whatever flags you need at the end...

This should do exactly what you're asking above, with or without a trailing forward slash.

Hope this helps.

Jun 11, 2009 at 7:12 PM

Thanks for the feedback but I have one more question: can it work with wildcards?

I mean, I cannot add rules to rewrite /temporary_contracts/index.cfm?loc=contact&lng=EN&CFID=86356&CFTOKEN=76213163 because the parameters of CFID and CFTOKEN are unique, but could I do something like /temporary_contracts/index.cfm?loc=contact&lng=EN&* to be rewritten to /temporary-contracts/contact/ ?

If that will work, that would be a solution.

Jun 11, 2009 at 8:14 PM

The solution offered by shonk works fine (at least for the rewriting) but I lose all the images on the pages and the stylesheets are not loaded anymore...

How can this be solved?

Jun 12, 2009 at 9:18 AM

You can make this work with wilcards.

RewriteRule ^/temporary-contracts/contact/([^/]*)/(.*)$ /temporary_contracts/index.cfm?loc=contact&lng=EN&CFID=$1&CFTOKEN=$2

would give you results like:

/temporary-contracts/contact/86356/76213163  ==>  /temporary_contracts/index.cfm?loc=contact&lng=EN&CFID=86356&CFTOKEN=76213163

/temporary-contracts/contact/1234/567890==>  /temporary_contracts/index.cfm?loc=contact&lng=EN&CFID=1234&CFTOKEN=567890

What this rule is saying is to take anything after /contact/ that isn't a / and put it in a variable that can be used later in the rewrite ($1) for CFID. Then *everything* after the / will be put in $2 for CFTOKEN.

You could just have this as /temporary-contracts/contact?CFID=1234&CFTOKEN=567890 if that would work better which should work with the original rule if you remove the $ after /contract/

If you've lost your images, then they are probably being referenced relative the document index.cfm (ie. starting just with the file or folder name eg. images/pic1.jpg). I you make sure that all your images start with a forward slash so that they're being referenced to root, this should solve this. (ie. /images/pic1.jpg). The same with the stylesheets. Feel free to send through a URL if you've got one up and working.

Hope this helps. Let me know how you get on.