Apache mod_rewrite problems with ColdFusion
By Pete Freitag
I have been trying to find the answer to an Apache mod_rewrite problem when using CFMX 6.1. I asked both the cf-linux list, and the cfguru list with no avail (Sean Corfield did suggest using mod_proxy to marshal requests to CF's builtin web server, but that was not ideal for my configuration).
Here's the issue, lets say you want to create search engine safe URLs that don't use file extensions - such as site.com/item/30/ which would redirect to something like: site.com/item.cfm?id=30. So I created a rewrite rule:
RewriteEngine On RewriteRule ^/item/([0-9]).*$ /item.cfm?id=$1
After creating that rule, and visiting site.com/item/30/ It outputs the CFML source code to item.cfm! When I try something like site.com/item/30.cfm it works! So clearly CFMX is not able to process the file unless I add .cfm to the url. It is interesting to point out that If I use a php file instead of a cfm file, it works fine.
Next I mapped the * url patteren to CfmServlet in the web.xml file. This did nothing but stop php from working.
Apache mod_rewrite problems with ColdFusion was first published on November 11, 2003.
The FuseGuard Web Application Firewall for ColdFusion & CFML is a high performance, customizable engine that blocks various attacks against your ColdFusion applications.
CFBreak
The weekly newsletter for the CFML Community
Comments
I'm joining this party *well* after it's ended, I know, but I'm hitting the same mod_rewrite issue. The problem is, my situation includes a twist: I can't use the [PT] flag because I need the CGI variables - specifically SCRIPT_NAME to retain the value from the original request. If I use the PT flag then the SCRIPT_NAME value becomes that of the landing page.
Is there a way to configure mod_rewrite to redirect requests for ^/(.*) to /foo.cfm such that the redirected request doesn't *have* to end in .cfm?
Thanks.
RewriteCond %{SERVER_PORT} !8080
RewriteRule /(.*) %{SERVER_PROTOCOL}://%{REQUEST_URI}:8080/$1
I should note that I haven't tested this at all. It may not be right, but it just might be close enough to get you moving in the right direction.
RewriteRule /stores/store/id/([0-9]+)(.*) /stores/store.cfm\?id=$1 [PT]
Notice the escape of the ? on the right hand side? And notice the use of [PT], which I forget what it means. Anyway, give it a try.