Apache and .cfm mod_rewrite not working

I would put that in a .htaccess file or make sure your rewrite rules are loaded after your mod_cfm or mod_proxy rules.

plus if your virtual host is running CFML, then you have to have the allow and order rules in the virtual host directive, or it will only work for your global default web configuration.

<VirtualHost *:80>
ServerName mydomain.com
ServerAlias www.mydomain.com
DocumentRoot /var/www/DocRoot
<Directory /var/www/DocRoot >
AllowOverride All
</Directory>
IfModule proxy_module
 ProxyPassMatch ^/(.+\.cf[cm])(/.*)?$ ajp://localhost:8009/$1$2
IfModule
RewriteEngine on 
ReWriteCond %{REQUEST_URI} !^/synth/cfman.cfm 
ReWriteCond %{REQUEST_URI} !^/synth/index.cfm RewriteRule ^synth/([^/.]+).cfm$ /synth/_inc/synth.cfm?file=$1 [L] 
ErrorLog /var/log/httpd/mydomain-error_log
CustomLog /var/log/httpd/mydomain-access_log common
</VirtualHost>

Thanks Terry, I’ll try that, though I’m a little confused as to which mod_ is doing the connecting now.
Below my virtual host for the site, there is this:

 <VirtualHost *:80>     
DocumentRoot /mydoc root 
ServerName mydomain.com
ServerAlias www.mydomain.com
RewriteEngine on
ReWriteCond %{REQUEST_URI} !^/synth/cfman.cfm 
RewriteRule ^synth/([^/.]+).cfm$ /synth/_inc/synth.cfm?file=$1 [L]
<Directory /opt/lucee/tomcat/webapps/sonicstate/sonicstate.com>
AllowOverride All
Order allow,deny
Allow from all
</Directory> 
<IfModule proxy_module.c>
ProxyPassMatch ^/(.+.cf[cm])(/.)?$ ajp://localhost:8009/$1$2 
</IfModule>
</VirtualHost>

<IfModule mod_proxy.c>
ProxyPreserveHost On
ProxyPassMatch ^/(.+\.cf[cm])(/.*)?$ http://127.0.0.1:8888/$1$2
ProxyPassMatch ^/(.+\.cfchart)(/.*)?$ http://127.0.0.1:8888/$1$2
ProxyPassMatch ^/(.+\.cfml)(/.*)?$ http://127.0.0.1:8888/$1$2
# optional mappings    
#ProxyPassMatch ^/flex2gateway/(.*)$ http://127.0.0.1:8888/flex2gateway/$1
#ProxyPassMatch ^/messagebroker/(.*)$ http://127.0.0.1:8888/messagebroker/$1
#ProxyPassMatch ^/flashservices/gateway(.*)$ http://127.0.0.1:8888/flashservices/gateway$1
#ProxyPassMatch ^/openamf/gateway/(.*)$ http://127.0.0.1:8888/openamf/gateway/$1
#ProxyPassMatch ^/rest/(.*)$ http://127.0.0.1:8888/rest/$1
ProxyPassReverse / http://127.0.0.1:8888/
</IfModule>
LoadModule modcfml_module modules/mod_cfml.so
CFMLHandlers ".cfm .cfc .cfml"
ModCFML_SharedKey "some random string"
LogHeaders false
LogHandlers false
LogAliases false
VDirHeader false

I think this gets auto added when installing Lucee (its been a while). does this seem right?
Its wierd, but on the dev server, if I comment out the ajp:// lines in the virtual host, CFM still gets served, I’m wondering if somehow this aint right…

It should be mod proxy and then your re-write rules.

OK, tried that, put the <IfModule mod_before the virtual host, put the rewrite rules after the proxy_module inside the virtualhost, restarted everything, cleared browser cache etc - still getting the problem with the cfm redirect rule, the resulting page appends the CFTOKEN and CFID to the url and throws a too many redirects error

Set mod_rerwite log to level 4
output is multiple lines like this, till I close the page.

(timestamp/IP stuff) init rewrite engine with requested uri /synth/accesindigo.cfm
 (timestamp/IP stuff) (1) pass through /synth/accesindigo.cfm
 (timestamp/IP stuff) (2) pass through /synth/accesindigo.cfm

You can see that its not applying the mod_rewrite rule this just enters loop of lines like this (1), (2) and we get the too many redirects loop. This is driving me a bit mad now.

Sorry about this, next test: I removed the rules from htaccess and put them directly in the virtual host, log just passes it through, applies no rules.

RewriteEngine on
ReWriteLog /opt/rw.log
ReWriteLogLevel 3
#Main directory path to cfm template (working)
ReWriteCond %{REQUEST_URI} !^/synth/cfman.cfm
ReWriteCond %{REQUEST_URI} !^/synth/index.cfm
ReWriteCond %{REQUEST_URI} !^/synth/cfsynth.cfm
RewriteRule ^synth/([^/.]+)/$ /synth/_inc/synth.cfm?file=$1 [L]

This block works in .htaccess, but not in the virtual host wrapper rules written in this block do not seem to apply at all

If it works in the .htaccess and not in the directive, then issue is where the DocRoot is for your virtual directive and when the rewrite rules are being applied.

Apache HTTPD Server configuration is applied sequentially.

You more than likely have your Virtual Directive applied before you have you have your load modcfml.

You need to switch it so your modcfml is loaded first, then your virtual configuration.

Thanks Terry, currently the order in httpd.conf is:

<IfModule mod_proxy.c>
ProxyPreserveHost On
ProxyPassMatch ^/(.+\.cf[cm])(/.*)?$ http://127.0.0.1:8888/$1$2 
ProxyPassMatch ^/(.+\.cfchart)(/.*)?$ http://127.0.0.1:8888/$1$2
ProxyPassMatch ^/(.+\.cfml)(/.*)?$ http://127.0.0.1:8888/$1$2
ProxyPassReverse / http://127.0.0.1:8888/
</IfModule>

LoadModule modcfml_module modules/mod_cfml.so
CFMLHandlers ".cfm .cfc .cfml" 
ModCFML_SharedKey "randomstringkey"
LogHeaders false
LogHandlers false
LogAliases false
VDirHeader false

then my virtual host block which contains the Directory info:

<VirtualHost *:80>
DocumentRoot /opt/lucee/tomcat/webapps/mydonain/mydomain.com
ServerName mydomain.com
ServerAlias www.mydomain.com
<Directory "/opt/lucee/tomcat/webapps/mydomain/mydomain.com/">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory>
<IfModule proxy_module.c>
ProxyPreserveHost On
ProxyPassMatch ^/(.+.cf[cm])(/.)?$ ajp://localhost:8009/$1$2
</IfModule>
RewriteEngine on
ReWriteLog /opt/rw.log
ReWriteLogLevel 3
#NEW BLOCK NB SYNTH MODELS (not working in htaccess_
ReWriteCond %{REQUEST_URI} !^/synth/cfman.cfm
ReWriteCond %{REQUEST_URI} !^/synth/index.cfm
ReWriteCond %{REQUEST_URI} !^/synth/cfsynth.cfm
RewriteRule ^synth/([^/.]+).cfm$  /synth/$1/ [L]
#Main directory path to cfm template (works in htacces but not here)
#ReWriteCond %{REQUEST_URI} !^/synth/cfman.cfm 
#ReWriteCond %{REQUEST_URI} !^/synth/index.cfm
#ReWriteCond %{REQUEST_URI} !^/synth/cfsynth.cfm 
#RewriteRule ^synth/([^/.]+)/$ /synth/_inc/synth.cfm?file=$1 [L]
</VirtualHost>

This is not working. According to what you are saying, it should right?

This should be

LoadModule modcfml_module modules/mod_cfml.so
CFMLHandlers ".cfm .cfc .cfml" ModCFML_SharedKey "randomstringkey"
LogHeaders false
LogHandlers false
LogAliases false
VDirHeader false

Then

Virtual Directive

Inside Virtual Directive

LoadModule modcfml_module modules/mod_cfml.so
CFMLHandlers ".cfm .cfc .cfml"
ModCFML_SharedKey 

Then the Rewrite Rules

Thanks again for your patience;
Okay so using that, I get an error when restarting the httpd - calling mode_cfml twice,
so I binned the call outside the virtual directive.
But the rewrite not working still from inside the virtual directive.

Just checking inside the virtual directive means this:

<VirtualHost etc...>
stuff
<Directory etc>
stuff
</Directory>
LoadModule modcfml_module modules/mod_cfml.so
CFMLHandlers ".cfm .cfc .cfml"
Rewrite stuff
</VirtualHost>

Yes that is how it should work.

Is this Ubuntu or RHEL / CEntos?

usually only two reasons mod_rewrite will not work in a directive but works perfectly as .htaccess file
bad order or bad permissions.

is Apache HTTPD and Lucee the same user or the same permissions group?

Its running on an Amazon EC2 linux image. I will check the permissions.

Thanks again

are you using HTTPD 2.2 or 2.4? IIRC, Apache changed some syntax between these 2 versions, especially as related to <Directory> blocks. We had issues when upgrading from 2.2 to 2.4

its 2.2.34

Weird, as this is the configuration on my test vm, and it works as expected.

What is Lucee running as and its Apache running as the same user or group?

I ask as I have the same configuration on a CENTOS 7 box I use for development.

I use user and group apache for lucee
and I have SELINUX disabled.

Yeah, I cant see why it is not working, I’m unable to get any rewriterules to work in the virtualhost.

Server is running apache under apache, lucee under root, starting to look like I might have to do a total rebuild of this server, I tried the lucee change user and it broke everything

Okay so I removed mod_cfml and just used mod_proxy, all called from the .htaccess instead. that seems to have fixed i.

Thanks for all your help

Nick

Glad to hear its working.

Nick - would you be willing to post the final config setup that worked for you? I’m struggling with something similar (htaccess being sort of ignored and url rewriting not working) albeit I’m on Windows and running Apache 2.4. I’m looking for any model that might get URL rewriting working for me.

I realize this is a post that is a few years old but I too would be interested in seeing the final config. I have tried all number of things, and this is the only post I can find that accurately describes the problem, with some suggested fixes, but none seem to work.

Getting the .htaccess to work is not the problem, it’s rewrites/redirects inside it that include a .cfm file (old files that need a redirect for example). I’m guessing this is related to the proxymatch side of things.

1 Like