Using RedirectMatch in .htaccess to redirect entire web site

Wednesday, March 5th, 2008

When changing websites, I was trying to use Apache’s RedirectMatch to send all documents from one domain to another domain. I used code that I found on other websites, but I found that it didn’t do what I wanted.

What I wanted was for a user to put in http://www.olddomain.com/a_file.html and be redirected to http://newdomain.com/a_file.html. I wanted it to do that for each file, and I didn’t want to specify a redirect for each file. I didn’t want to use mod_rewrite because I wanted to give the 301 redirect for Search Engine Optimization (SEO) reasons.

Quick Answer: use RedirectMatch permanent ^(.*)$ http://www.newdomain.com$1 in a .htaccess file in your old domain.

Read the rest of this article »