Redirecting Multiple Web Pages with a Wildcard

by Michael on September 2, 2012 · 0 comments

I recently ran into a situation where I needed to redirect multiple web pages with the same basic url structure to another domain. While I could create a bunch of individual 301 redirects, it would be easier to use a catchall. But how?

At first I wasn’t sure, so I did what I usually do… I turned my attention to Google. And once again, Google delivered.

The following bit of code, when placed in .htaccess, will redirect any links from the originating domain that are immediately followed by “/archives/” and then anything else to another url — in this case

RedirectMatch 301 ^/archives/.*$

You can, of course, tweak both the originating url structure as well as the target url to fit your needs. In this case, it just points to the top-level domain, but there’s no reason it can’t point to an internal page.

{ 0 comments… add one now }

Leave a Comment

Previous post:

Next post: