mod_rewrite or mod_alias?
Asked Answered
E

2

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?

Egor answered 30/4, 2009 at 17:4 Comment(1)
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 fileEgor
I
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.

Iconoclast answered 30/4, 2009 at 17:20 Comment(3)
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.Egor
"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.Trigeminal
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. – 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.Thimerosal
C
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.

Coed answered 14/7, 2019 at 16:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.