Beginner Fundamentals
Redirects
A redirect tells the browser to request a different URL. Apache offers simple redirect directives from the mod_alias module, which is enabled by default.
The Redirect Directive
# Send one path to a new location
Redirect /old-page.html /new-page.html
You can also redirect to a full URL on another domain:
Redirect /docs https://docs.example.com/
Permanent vs Temporary
Add a status to tell browsers and search engines whether the change is permanent:
Redirect permanent /old https://example.com/new
Redirect temp /promo https://example.com/sale
permanent sends a 301; temp sends a 302.
RedirectMatch
RedirectMatch uses a regular expression for flexible patterns:
# Redirect every .htm file to its .html version
RedirectMatch 301 ^/(.*)\.htm$ /$1.html
The captured group (.*) is reused as $1 in the target.
Apply Changes
sudo apache2ctl configtest
sudo systemctl reload apache2
For simple moves, use Redirect. For complex rules, RedirectMatch or mod_rewrite give more control.