Forum Topic: mod_alias (redirect/redirectmatch) & mod_rewrite in same file

Forum: .htaccess Forum : Redirecting • Posted by Cyndi • Updated:

In my “redirect” knowledge search (I’m so glad I now found your book), I have seen it said that one should not use both mod_alias and mod_rewrite in the same .htaccess file. I’ve just finished the redirect chapter in your book and didn’t see it mentioned which makes me wonder if it is indeed true that you shouldn’t mix the two.

I have a TON of redirects due to a site overhaul and am trying to clean up my .htaccess (which is a mess!) and while most redirects are one-to-one redirects leading me to consider mod_alias, there are some where the more sophisticated rules of mod_rewrite would be needed.

Any thoughts on this?

4 Replies to “mod_alias (redirect/redirectmatch) & …”

Posted by Jeff Starr

Interesting but it’s not something that I’ve ever heard, read or experienced. I use all sorts of redirects and rewrites in my own .htaccess files, and have been doing so for years now with absolutely zero issues because of it. If you can provide a source for such claims, I would be interested in reading it; there may be some theoretical reasoning behind the idea, but in practice it’s fine to use both.

Posted by Cyndi •

Here is one of the places that mentioned it…

https://www.webmasterworld.com/apache/4056927.htm

It seems that the main issue is something about the order in which they are executed.

By the way, if mod_alias is available, but not turned on, how do you enable it in the .htaccess file? Is it AliasEngine like mod_rewrite or something else? (should this have been another thread?) :)

Posted by Jeff Starr

Interesting, but there is no real explanation provided and it seems to not make sense given this from the Apache Docs:

“Aliases and Redirects occurring in different contexts are processed like other directives according to standard merging rules. But when multiple Aliases or Redirects occur in the same context (for example, in the same section) they are processed in a particular order.”

“First, all Redirects are processed before Aliases are processed, and therefore a request that matches a Redirect or RedirectMatch will never have Aliases applied. Second, the Aliases and Redirects are processed in the order they appear in the configuration files, with the first match taking precedence.”

It may be inferred from that passage that it’s fine to mix-n-match redirects and rewrites as needed.

For enabling mod_alias, there is no way that I know of to do it from .htaccess — it must be enabled/disabled via the Apache configuration file.

Posted by Cyndi •

That makes sense to me.

Thank you so much!