Apache mod_rewrite problems with ColdFusion

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.
Trackbacks
Trackback Address: 22/B3D2D1048E829EAD1106F4691C95E55A
Comments
On 11/11/2003 at 3:29:43 PM EST Raymond Camden wrote:
1
I see some things in your rewrite rule that looks different then mine, and since mine works fine (although on Windoze), I thought I'd share. Here is one of my rules:
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.
On 11/11/2003 at 11:36:25 PM EST Pete Freitag wrote:
2
Thanks Ray I'll give it a try, BTW it looks like [PT] stands for pass through: from the docs "This flag forces the rewriting engine to set the uri field of the internal request_rec structure to the value of the filename field. This flag is just a hack to be able to post-process the output of RewriteRule directives by Alias, ScriptAlias, Redirect, etc. directives from other URI-to-filename translators."
On 12/08/2003 at 2:26:32 AM EST Sean Corfield wrote:
3
I think adding [R,L] to the RewriteRule might also solve your problem - that forces a redirect to the browser (a 302) so that the request comes back as if the user had typed it in directly (so it should be processed correctly by CF).
On 11/29/2004 at 11:02:28 PM EST Chris Bestall wrote:
4
This post is somewhat old, but in case others find it like I did...I got it to work using Ray Camden's suggestion of [PT]. I also added [L] to end up with [PT,L], and this is working for me using Linux and Bluedragon 6.2.
On 01/31/2005 at 2:57:40 PM EST Nick Walters wrote:
5
To echo Chris Bestall, this worked for me (thank God) by adding [PT,L] to the RewriteRule line, but for Apache2/Windows.
On 05/21/2005 at 7:18:03 AM EDT SpliFF wrote:
6
Doing a 302 redirect will slightly slow down your site since it forces browsers to make two requests for each page. Is L really required or will PT do?
On 05/21/2005 at 1:26:18 PM EDT Pete Freitag wrote:
7
SpliFF - The L is not required, it simply means stop processing rules after this one (if it matches), so in many cases you want it, but in some you don't.
On 05/22/2005 at 9:48:03 AM EDT SpliFF wrote:
8
Thanks Pete, The following works beautifully for me (Apache2/Linux)...
# Only if request has no extension do we pass to /index.cfm. This means static content like .js,.gif,.html etc.. are handled normally by Apache.
RewriteEngine On RewriteCond %{REQUEST_FILENAME} !^.*?\.[^/]{2,5}$ RewriteRule (.*) /index.cfm$1 [PT]
My code retrieves values from both cgi.path_info and cgi.query_string which means it also captures the old non-seo requests without problems.
Note to Pete: Your blog doesn't work with referer turned off in browser.
On 05/22/2005 at 9:49:51 AM EDT SpliFF wrote:
9
Oops, linefeeds went awol, should be...
RewriteEngine On RewriteCond %{REQUEST_FILENAME} !^.*?\.[^/]{2,5}$ RewriteRule (.*) /index.cfm$1 [PT]
On 05/22/2005 at 9:53:26 AM EDT SpliFF wrote:
10
Hmmm. again... well you all get the idea. If not you're boned away. ;)
On 07/05/2006 at 1:05:54 PM EDT Rob Wilkerson wrote:
11
Hey guys -
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.
On 10/27/2006 at 12:00:35 PM EDT Paul Fiero wrote:
12
I have a problem that is slightly different from what you all have here but I'm hoping someone can assist.
I'm attempting to use mod_rewrite to redirect all incoming .cfm requests (index.cfm, default.cfm, login.cfm, etc) to an actual CF server using it's own HTTP server on port 8080.
Anyone willing to offer up a shot? Respond here or by e-mail....I'd appreciate whatever I can get.
PFiero
On 10/27/2006 at 12:24:08 PM EDT Rob Wilkerson wrote:
13
Try
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.
On 10/27/2006 at 12:55:12 PM EDT Paul Fiero wrote:
14
Good thought but this server also hosts a ton of other regular web page stuff. Here is what I have so far:
RewriteEngine on RewriteLog "/var/log/httpd/rewrite.log" RewriteLogLevel 9 RewriteRule (/.*\.cfm.*) http\://10.74.52.35\:8080$1 [P]
# Fix final slash for /dir RewriteCond Host: (.*) RewriteRule ([^.?]+[^.?/]) http\://$1$2/ [R]
# Append default.cfm to any dir RewriteRule ((?!.+\.cfm).*/) $1default.cfm [P]
And by the way if I type the URL with the .cfm page on it.... http://www.example.com/default.cfm for instance, the page comes up now. But if I put just http://www.example.com/ it gives me an error.
On 10/28/2006 at 12:59:48 AM EDT SpliFF wrote:
15
You may need to modify web.xml or default-web.xml under the coldfusion wwwroot directory and put in something like this:
<servlet-mapping> <servlet-name>CfmServlet</servlet-name> <url-pattern>*.cfm/*</url-pattern> </servlet-mapping>
Its been a long time since I did this but I believe it was required for redirected URLs that don't end in .cfm. It seems jrun doesn't realise its supposed to be handling it because it looks at the original URL, not the [PT] one.
On 10/22/2009 at 10:57:45 AM EDT GanjaBoy22 wrote:
16
But after a day or so it is noticed that the pure water, owing to its higher vapour pressure, slowly evaporates and condenses on the solution. ,
Post a Comment
Recent Entries
- Cache Template in Request Setting Explained
- What Version of Java is ColdFusion Using?
- ColdFusion 9 Performance Brief from Adobe
- Request Filtering in IIS 7 Howto
- J2EE Session Cookies on ColdFusion / JRun
- Hands on ColdFusion Security Training
- ColdFusion 9 Solr Vulnerability - Are you at Risk?
- FCKEditor Year 2010 Bug for Firefox 3.6 with ColdFusion
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.
# Only if request has no extension do we pass to /index.cfm. This means static content like .js,.gif,.html etc.. are handled normally by Apache.
RewriteEngine On RewriteCond %{REQUEST_FILENAME} !^.*?\.[^/]{2,5}$ RewriteRule (.*) /index.cfm$1 [PT]
My code retrieves values from both cgi.path_info and cgi.query_string which means it also captures the old non-seo requests without problems.
Note to Pete: Your blog doesn't work with referer turned off in browser.
RewriteEngine On RewriteCond %{REQUEST_FILENAME} !^.*?\.[^/]{2,5}$ RewriteRule (.*) /index.cfm$1 [PT]
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.
I'm attempting to use mod_rewrite to redirect all incoming .cfm requests (index.cfm, default.cfm, login.cfm, etc) to an actual CF server using it's own HTTP server on port 8080.
Anyone willing to offer up a shot? Respond here or by e-mail....I'd appreciate whatever I can get.
PFiero
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.
RewriteEngine on RewriteLog "/var/log/httpd/rewrite.log" RewriteLogLevel 9 RewriteRule (/.*\.cfm.*) http\://10.74.52.35\:8080$1 [P]
# Fix final slash for /dir RewriteCond Host: (.*) RewriteRule ([^.?]+[^.?/]) http\://$1$2/ [R]
# Append default.cfm to any dir RewriteRule ((?!.+\.cfm).*/) $1default.cfm [P]
And by the way if I type the URL with the .cfm page on it.... http://www.example.com/default.cfm for instance, the page comes up now. But if I put just http://www.example.com/ it gives me an error.
<servlet-mapping> <servlet-name>CfmServlet</servlet-name> <url-pattern>*.cfm/*</url-pattern> </servlet-mapping>
Its been a long time since I did this but I believe it was required for redirected URLs that don't end in .cfm. It seems jrun doesn't realise its supposed to be handling it because it looks at the original URL, not the [PT] one.



add to del.icio.us



