Forum Topic: Redirecting entire site, leaving dev site accessible temporarily

Forum: .htaccess Forum : Redirecting • Posted by Bill Joseph • Updated:

I currently have a site that needs to be "mothballed", and all page requests redirected to a new website. The current site can be accessed three ways:

oldsite.com
www.oldsite.com
oldaccountname.servername.com

I would like to leave the old site in place (accessible to the site admins) temporarily while we make sure all the content has been addressed, so what I'd like to do is redirect the www and non-www domain name requests to the new site, but leave the oldaccountname.servername.com address able to access the old site.

I'm thinking I should use mod_rewrite, adding this to the .htaccess file:

RewriteCond %{HTTP_HOST} ^oldsite\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.oldsite\.com$
RewriteRule ^(.*) http://www.newsite.com/$1 [R=301,L]

If I add this to the top of my htaccess file (after RewriteEngine On), it will handle all requests using the oldsite.com and www.oldsite.com urls, while allowing the server-based url to continue through to the already established SEF Rewriting directives. Is that right?

Thanks!

2 Replies to “Redirecting entire site, leaving dev site …”

Jeff Starr
Posted by Jeff Starr

Hi Bill,

Yes that looks good, and you can even whitelist the oldaccountname.servername.com like so:

RewriteCond %{HTTP_HOST} !^oldaccountname\. [NC]

There are some other tweaks that can be made as well, for example:

RewriteCond %{HTTP_HOST} ^(www\.)?oldsite\.com [NC]
RewriteRule ^(.*) http://www.newsite.com/$1 [R=301,L]

This combines the two oldsite rules into one, and removes the $ to account for any possible variations.. putting all three lines together gives this:

RewriteCond %{HTTP_HOST} !^oldaccountname\. [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?oldsite\.com [NC]
RewriteRule ^(.*) http://www.newsite.com/$1 [R=301,L]

Further fine-tuning is possible but that should definitely get you there.

Posted by Bill Joseph •

Thanks, Jeff, I'm going to try your solution - a bit more elegant than mine!!

Thanks for having our backs on questions like these. Makes it less daunting!