Last Updated: 14 Oct 2023
|
Apache: Rewrite vs Redirect
Apache has two ways to serve one page when you were asked for another: Rewrite*
rules via mod_rewrite (e.g. RewriteRule
, RewriteCond
), and Redirect*
rules via mod_alias (e.g. Redirect
and RedirectMatch
).
What are the differences?
mod_rewrite
is generally considered the more powerful, and more complex, solution. It offers theRewriteCond
directive, which lets you only run a Rewrite rule if certain conditions are met.mod_alias
is simpler, and lets you match on a simple string or on a regular expression, but does not allow you to put conditions in (other than those defined by the regexp)
Discussion