Forum Moderators: phranque

Message Too Old, No Replies

Apache mod_rewrite - Return dynamic page from handler from static call

         

Double_Dark

10:20 pm on Apr 14, 2005 (gmt 0)

10+ Year Member



Apache Server 1.3.something
Cold Fusion Server MX 7

It seems that on setup Cold fusion adds a handler for a few filetypes, .cfm among them.

Say I have a page <some_url>/b.cfm that returns some dynamic content.

Then say I want all .html pages to actually go to b.cfm

So <some_url>/a.html should actually return <some_url>/b.cfm.

So I add the following to the virtual host

RewriteEngine on
RewriteRule ^.+\.html /b.cfm [NC]

The server redirects just fine. The problem is that b.cfm is just returned without being processed by Cold Fusion so say instead of getting the current date I get #now()#.

How do I get the dynamic content?

Is it possible to do what I'm trying to do and if so how?

sitz

11:26 pm on Apr 14, 2005 (gmt 0)

10+ Year Member



So, the first thing you have to realize is that Apache passes each phase of a given HTTP request to each of the modules in it's config file (or each one it's compiled against, if the modules are hard-compiled) in *reverse* order from how they appear. I've not played with coldfusion at all (praise be to $DEITY), but as I see it you have two options, one (or both) of which may actually work. =)

  • Ensure that mod_rewrite appears /after/ the loading of the ColdFusion module;
  • Add 'PT' to the flags in your RewriteRule. Note that you should also have an 'L' in there, so your Rule would become:

    RewriteEngine on
    RewriteRule ^.+\.html /b.cfm [NC,PT,L]

    That said, I'd probably tweak it this way:


    RewriteEngine on
    RewriteRule \.html$ /b.cfm [NC,PT,L]

    Finally, note that the use of the 'PT' flag may well have unexpected consequences; test thoroughly. =)

    (if 'PT' doesn't work, or breaks stuff, I'd still use my latter Rule with it removed, BTW)

  • Double_Dark

    1:31 pm on Apr 15, 2005 (gmt 0)

    10+ Year Member



    Thank you. Adding the PT made it work correctly.