Recursive .htaccess redirects

Recently I came across a request on Twitter for an effective means to update the .htaccess file to redirect all pages to a new domain without having to update for all subdirectories.  Here are a couple choices which can be easily placed in the root .htaccess file.

OPTION 1 (this does not need the RewriteEngine module)

Option 2 (this requires the use of the RewriteEngine module)

  • Options +FollowSymLinks
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^oldwebsiteaddress.com$ [OR]
    RewriteCond %{HTTP_HOST} ^www.oldwebsiteaddress.com$
    RewriteRule (.*)$ http://www.YourNewDomainAddressHere.com/$1 [R=301,L]
Be Sociable, Share!