26

I have a server, its httpd.conf already has some "RedirectMatch permanent" directives in it.

I'm not that familiar with mod_alias, I've only ever used mod_rewrite.

What's the basic difference? I don't see a "L" flag in mod_alias to stop processing rules.

Which one should I use for best practices of redirecting from one sub-domain to another?

Can I use both at the same time and will it be obvious which takes precedence?

xav
  • 5,452
  • 7
  • 48
  • 57
jeph perro
  • 6,242
  • 26
  • 90
  • 124
  • I have found out in the end that mod_rewrite is more powerful and is a superset of mod_alias. I was able to successfully use both mod_alias and mod_rewrite rules in the same httpd.conf file – jeph perro Apr 30 '09 at 18:57

2 Answers2

22

mod_alias is basically a simpler version of mod_rewrite. It can't do some things that mod_rewrite can, such as manipulate the query string. If you're able to choose either of them, I don't see any reason that you'd want to use mod_alias.

Is there a specific reason you need to try to use both together?

Apache mod_rewrite & mod_alias tricks you should know seems to be a good article about the two. It notes at one point that mod_rewrite rules get executed before mod_alias ones.

Palec
  • 12,743
  • 8
  • 69
  • 138
Chad Birch
  • 73,098
  • 23
  • 151
  • 149
  • The only reason I want to use both together, is that there are about 30 existing rules using mod_alias. I've written my own mod_rewrite rules that I'd like to add, and I'd rather not have to recreate the existing rules in mod_rewrite. – jeph perro Apr 30 '09 at 17:28
  • "mod_rewrite rules get executed before mod_alias ones." - Wish that gem was in the apache documentation. In my setup using both rewrite and alias; that's exactly what I'm now observing. – txyoji Nov 04 '20 at 22:18
  • 2
    Official documentation: “**mod_rewrite should be considered a last resort**, when other alternatives are found wanting. Using it when there are simpler alternatives leads to configurations which are confusing, fragile, and hard to maintain.” [_When not to use mod_rewrite_](https://httpd.apache.org/docs/trunk/rewrite/avoid.html). – Using the most powerful system simplifies decisionmaking but is often not the best approach to good maintainability. There are good reasons to skip mod_rewrite for mod_alias. mod_alias should be the primary choice. – Kissaki Mar 08 '21 at 13:44
4

As the accepted answer says: mod_rewrite can do things which mod_alias can't. However the main benefit of mod_alias is that it is easier to use.

The apache docs say that we should use mod_alias for simple things like redirects and mod_rewrite only for things we cannot do with simpler modules like mod_alias. View the docs: When not to use mod_rewrite.

Michael Käfer
  • 1,597
  • 2
  • 19
  • 37