14

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.

2 Answers 2

8

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.

2
  • As ptman already mentioned, with mod_rewrite you can do crazy stuff like dynamic routing to a proxy. This is sometimes very handy and you can connect to a proxy-cluster with one command instead of multiple mod_proxy lines. But is more complex and sometime not easy to debug. Commented Sep 25, 2010 at 10:15
  • 1
    According to the Apache documentation, performance will be better using mod_proxy directly with the ProxyPass or ProxyPassMatch directives. Commented Sep 15, 2021 at 22:30
5

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)
1

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.