htaccess not working as mod_proxy precedes mod_rewrite. Any solution?

37 views
Skip to first unread message

Andy Yu

unread,
Jun 3, 2016, 3:58:30 PM6/3/16
to mod_cfml
I'm currently using Railo with mod_cfml that came with it. However one thing I've noticed is that htaccess doesn't work on cfml files because mod_proxy took over the request before mod_rewrite does. I found several possible workarounds to this problem but i wanted to know if anyone have a simple fix to this problem? Perhaps a new update can resolve it?

My possible workarounds are

1. Change the module name for mod_proxy so it loads after mod_rewrite. (Apache loads module by alphabetic order)
2. Disable mod_proxy and use mod_rewrite to do the proxy routing.
3. Change mod_proxy to mod_jk? Other users have suggested mod_jk works with htaccess.

Any help would be greatly appreciated!

 


Sean Daniels

unread,
Jun 3, 2016, 4:06:48 PM6/3/16
to mod_...@googlegroups.com
I can confirm that before I switched to nginx I would use mod_jk instead of mod_proxy to work around this exact issue.

That'd be my suggestion.
> --
> You received this message because you are subscribed to the Google Groups "mod_cfml" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to mod_cfml+u...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Jordan Michaels

unread,
Jun 3, 2016, 4:18:30 PM6/3/16
to mod cfml
Yep, it's an order of execution problem, and none of the solutions are really ideal in my opinion. Another solution would be to move the proxy config from the main apache config and add it to each .htaccess, but that adds a lot of exra work if you have a lot of sites to manage, and I've never personally used that method, so I'm not sure how well it works.

I've personally used both the mod_jk method and the mod_rewrite method. Mod_jk is a great connector, but it's quite a bit more complicated than mod_proxy in that there are several files to manage with it. Switching to mod_rewrite was fairly simple as you still only have to edit the one config, but it's not as well documented.

--
Kind regards,
Jordan Michaels
Vivio Technologies

Andy Yu

unread,
Jun 3, 2016, 5:36:38 PM6/3/16
to mod_cfml
Thanks for quick replies guys.

I've installed and enabled mod_jk. However i am still trying to figure out how to configure the whole thing. Do i only need to update apache2.conf and add "<IfModule>....<IfModule>" for mod_jk to work? Is there anything else i need to change like in tomcat, or mod_cfml?

Any instruction and sample code for apache2.conf would be very helpful!

Jordan Michaels

unread,
Jun 3, 2016, 6:33:38 PM6/3/16
to mod cfml
Paul did a post about it a long time ago... yeah. Here you go:

http://www.lucee.nl/post.cfm/how-to-add-mod-jk-to-apache-for-tomcat-railo

As for mod_cfml - it operates completely independent of whatever connector you're using, so it's config doesn't need to change at all.
> > On Jun 3, 2016, at 2:58 PM, Andy Yu <inam...@gmail.com <javascript:>>
> wrote:
> >
> > I'm currently using Railo with mod_cfml that came with it. However one
> thing I've noticed is that htaccess doesn't work on cfml files because
> mod_proxy took over the request before mod_rewrite does. I found several
> possible workarounds to this problem but i wanted to know if anyone have a
> simple fix to this problem? Perhaps a new update can resolve it?
> >
> > My possible workarounds are
> >
> > 1. Change the module name for mod_proxy so it loads after mod_rewrite.
> (Apache loads module by alphabetic order)
> > 2. Disable mod_proxy and use mod_rewrite to do the proxy routing.
> > 3. Change mod_proxy to mod_jk? Other users have suggested mod_jk works
> with htaccess.
> >
> > Any help would be greatly appreciated!
> >
> >
> >
> >
> >
> > --
> > You received this message because you are subscribed to the Google
> Groups "mod_cfml" group.
> > To unsubscribe from this group and stop receiving emails from it, send
> an email to mod_cfml+u...@googlegroups.com <javascript:>.
> > For more options, visit https://groups.google.com/d/optout.
>
> --
> You received this message because you are subscribed to the Google Groups
> "mod_cfml" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to mod_cfml+u...@googlegroups.com <javascript:>.

Andy Yu

unread,
Jun 3, 2016, 7:46:57 PM6/3/16
to mod_cfml
Thanks a lot Jordan

Yea, i did follow that post and have successfully switched to mod_jk. However it still doesn't process the htaccess file when it comes to cfm files, any idea?

Jordan Michaels

unread,
Jun 6, 2016, 3:33:22 PM6/6/16
to mod cfml
Hi Andy,

Hmm... it's still probably an order-of-execution problem. I wonder if this has to do with how you're implementing the .htaccess file. Are you using it to define your default document and so forth or are you JUSt using it for things like re-writes?

Andy Yu

unread,
Jun 6, 2016, 3:42:22 PM6/6/16
to mod_cfml
I did a very simple test for rewrite but it didn't work. I wonder if there is any setting i need to change in mod_jk module..

Here is a simple rewrite in htaccess file, it worked well if i disabled mod_jk.

RewriteEngine on
RewriteRule ^index.cfm$ test.cfm

Jordan Michaels

unread,
Jun 6, 2016, 4:20:19 PM6/6/16
to mod cfml
I wonder if it would help if you moved the "DirectoryIndex index.cfm" from your Apache config to your .htaccess config. Would you be willing to try that? If it DOESN'T work, let me know, and I'll do some more research to try to help you in a test environment. I'm sure you can't be the only person to want this kind of thing so we as a community should be able to have a good answer for you.

Mod_jk is just a handler, so I'm hoping by moving the DirectoryIndex to the .htaccess you don't trip the handler until after the .htaccess is processed. Let me know if changing the location of the DirectoryIndex value changes things.

Paul Klinkenberg

unread,
Jun 6, 2016, 6:40:54 PM6/6/16
to mod_...@googlegroups.com
Hi Andy,

Another thing you should try, is to set the Pass-Through flag to your rewrites, like this:

RewriteEngine on
RewriteRule ^index.cfm$ test.cfm [PT]

Hope that helps, kind regards,

Paul Klinkenberg


Andy Yu

unread,
Jun 8, 2016, 4:40:31 PM6/8/16
to mod_cfml
Thanks again guys.

I haven't been able to try out the suggestions yet because it turns out i haven't even been able to get mod_jk working properly.

Because apparently the tutorial for setting up mod_jk was for tomcat 6, tomcat 7 removed "ApacheConfig auto-generation functionality"

This line in server.xml will throw error, so don't bother if you are trying to get it to work on Tomcat 7....
"<Listener className="org.apache.jk.config.ApacheConfig" modJk="/usr/lib/apache2/modules/mod_jk.so" workersConfig="/etc/apache2/workers.properties" />"

Here is the error message..

Jun 08, 2016 8:28:15 PM org.apache.catalina.startup.Catalina load
WARNING: Catalina.start using conf/server.xml: Error at (124, 154) : org.apache.jk.config.ApacheConfig
Jun 08, 2016 8:28:15 PM org.apache.tomcat.util.digester.Digester startElement
SEVERE: Begin event threw exception              start(Bootstrap.java:321)
java.lang.ClassNotFoundException: org.apache.jk.config.ApacheConfig    5
        at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.catalina.startup.Catalina start
        Cannot start server. Server instance is not configured.)

Andy Yu

unread,
Jun 8, 2016, 6:02:18 PM6/8/16
to mod_cfml
Just an update, i was able to get mod_jk working with tomcat 7 with apache 2.4.7 working by removing the line "<Listener className="org.apache.jk.config.ApacheConfig" modJk="/usr/lib/apache2/modules/mod_jk.so" workersConfig="/etc/apache2/workers.properties" />" that was added to server.xml through the tutorial.

However i still couldn't get htaccess file to work before the proxy hits. I was rather surprised that not many people talked about this issue, since mod_rewrite has been pretty common for any web related projects and anyone who uses Railo + mod_rewrite will encounter this issue.

Paul Klinkenberg

unread,
Jun 9, 2016, 4:40:20 AM6/9/16
to mod_...@googlegroups.com
Hi Andy,

I suddenly saw you wrote "I'm currently using Railo with mod_cfml that came with it." 
You really mean "Railo", not "Lucee"? If so, you are using a much outdated version of mod_cfml. (and of Railo as well; it's last change is 1.5 years ago.)

One change between your version, and the most recent version of mod_cfml, will be of particular interest to your problem. It is a change in the order of which Apache modules are handled:
You don't have to understand the C code, but it's explanation is "Make sure this handler (mod_cfml) is called before mod_proxy / mod_jk is called, by setting hook order to APR_HOOK_FIRST - 1"

So... go download the latest mod_cfml Apache module and also Tomcat module at http://www.modcfml.org/index.cfm/downloads/
and install it on your system: http://www.modcfml.org/index.cfm/install/
Don't forget to remove the old tomcat mod_cfml.jar!

Kind regards,

Paul Klinkenberg
Reply all
Reply to author
Forward
0 new messages