Redirect Many URL to One URL in Apache

I recently faced a situation wherein I have to permanently redirect a list of URLs to a single URL. I’m used to doing it for 1 to 1 redirects(1 url to another) but this is the first time I did it for a lot of URL.


will need to be redirected to:

The solution? Use the RedirectMatch directive in Apache. It’s so easy to use. Use the syntax:

RedirectMatch [status] regex URL

where status is 301(permanent redirect) or if not used will 302(temporary redirect) which can be used in you Apache’s server config, virtual host, directory or .htaccess context.

In the above example, the exact RedirectMatch is:

RedirectMatch 301 ^/oldschool/(.*)

NOTE: First published in my now defunct blog.

comments powered by Disqus