tip for Apache's Redirect Function

apacheA project's website of our company has been running for a period of time, we ever changed several domains for this website before. Now,we want a smooth transition to a new domain names, that relates to the issue of old links turn to new links automatically for the new domain.

Assuming the previous domain names is www.old.com ,and the new domain name is www.new.com, now what we want is that any of links like www.old.com / xxx / yyy.htm will automatically jump to www.new.com / xxx / yyy.htm while we visit them.

First of all, because there are so many pages similar yyy.htm , it is impossible to change the links manually , and secondly, because we need to let visitors see the transition of domain,we can not use Rewrite moudle .

For that case,we can use the Apache Redirect function to realize the old links tures to new links automatically.

Implementation is very simple, only need to modify related codes of httpd.conf as below:

ServerName www.old.com
DocumentRoot /path/to/htdocs
......

RedirectMatch permanent ^/(.*)$ http://www.new.com/$1

The most crucial codes written in the above is that we should pay attention to match the domain name by using the "^/(.*)$", rather than "^ http://www.old.com/ (. *)$".

Creative Commons License
linuxine.com's blog posts is licensed under a Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 United States License