5.8. Redirecting Several URLs to the Same Destination
Problem
You want to redirect a number of URLs to the same place. For example, you want to redirect requests for /fish and /Fishing to http://fish.example.com/.
Solution
Use RedirectMatch in httpd.conf to match against a regular expression:
RedirectMatch "^/[fF]ish(ing)?(/.*)?" "http://fish.example.com/$2"
Discussion
This recipe redirects requests on one server for URLs starting with fish or fishing, with either an upper-case or lower-case f, to a URL on another server, fish.example.com. As with Redirect, the path information, if any, is preserved. That is, a request for http://original.server/Fishing/tackle.html is redirected to http://fish.example.com/tackle.html so that existing relative links continue to work.
As with several of the earlier examples, RedirectMatch uses regular expressions to provide arbitrary text pattern matching.
See Also
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access