Apache mod_proxy vs mod_rewrite

What is the difference between using mod_proxy and mod_rewrite?

I have a requirement to send certain url patterns through the tomcat, which runs on the same host but under port 8080. I know this is something for mod_proxy, but I"m wondering why I can't just use mod_rewrite, or what the difference is?

Probably has to do w/ reverse proxy, and also when in the pipeline it gets handled?

Thanks.


mod_rewrite using the P flags puts the request through mod_proxy. The advantage in using mod_rewrite is that you get more control for mapping requests, just like rewrite let's you rewrite URLs. But the proxying is exactly the same. The disadvantage is that mod_rewrite syntax is more complex. So my recommendation is to use mod_proxy -style configuration directives unless you need something more complicated. Others will probably recommend mod_rewrite -style, because then you only have to learn one style.


mod_rewrite is very general and very powerful: it can handle not only proxying but also aliasing, redirection, and pretty much any sort of custom mapping of URLs to either other URLs or filenames. (Well, I suppose if you looked hard enough you could find something mod_rewritecan't do) But there are several potential reasons not to use it:

  • You might not want to deal with the complexity of mod_rewrite. It is notoriously tricky to configure properly - the configuration is practically a programming language in itself.
  • Apache takes time to process all those complex rewriting rules, and if you have a busy server that may be something you don't want to deal with. Using mod_proxy directly allows you to invoke more streamlined code that might help your server run faster. (Honestly, I'm not sure how large of an effect this is, but I don't think it's that major)