$ a2query -m rewrite
rewrite (enabled by site administrator)
$ a2query -m rewrite
No module matches rewrite
$ a2enmod rewrite
Enabling module rewrite.
To activate the new configuration, you need to run:
systemctl restart apache2
httpd.conf) or virtual host configuration..htaccess file.
Source: A beginner’s guide to creating redirects in an .htaccess file
mod_aliasRedirect or RedirectMatch will never have Aliases applied.Example:
Redirect permanent "/one" "http://example.com/two"
Redirect 301 "/three" "http://example.com/other"
RedirectMatch permanent "(.*)\.gif$" "http://other.example.com$1.jpg"
Source: Apache Module mod_alias
mod_rewriteThe main difference is that, with mod_alias, the server is responding to the client request with a redirect, so the client immediately is sent to the new location. Conversely, with mod_rewrite, the server simply returns the new content, so the client is not actually redirected anywhere. This makes mod_rewrite more advantageous because it happens transparently, requiring less work from the client (user).
Source: Difference between mod_alias and mod_rewrite
RewriteEngine on
RewriteRule "^/foo\.html$" "/bar.html" [PT]
Execution order:
do
execute server and vhost rewrites (in the Apache Virtual Host Config)
find the lowest "Per Dir" .htaccess file on the file path with rewrites enabled
if found(.htaccess)
execute .htaccess rewrites (in the user's directory)
while rewrite occurred
mod_rewritemod_rewrite.htaccessmod_rewritemod_rewriteCan be set in server configuration (httpd.conf), virtual host configuration or directory configuration but not in .htaccess:
LogLevel alert rewrite:trace3
Then restart Apache:
$ systemctl restart apache2
$ tail -f error_log|fgrep '[rewrite:'