I have a WordPress site installed at http://www.example.com and another testing WordPress site at http://test.example.com. I've successfully made http://www.example.com redirect to http://beta.example.com with this .htaccess code:

RewriteCond %{HTTP_HOST} !^beta\.example\.com
RewriteRule ^(.*)$ http://beta.example.com/$1 [R=301,L]

However, when trying to go to http://test.example.com it forces it to http://beta.example.com/test/ with a 404 error. Is there a way to have this beta redirect but still keep my WordPress site at http://test.example.com working?


If I am understanding you correctly and you want test.example.com to still go to test.example.com. You can add another condition and both conditions will have to be met for the rule to be followed. It would look like:

RewriteCond %{HTTP_HOST} !^beta\.example\.com
RewriteCond %{HTTP_HOST} !^test\.example\.com
RewriteRule ^(.*)$ http://beta.example.com/$1 [R=301,L]

Now neither beta nor test subdomains will redirect, but ALL others will.

If you only want www.example.com or example.com to go to the beta subdomain you could use

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

There is a nifty tool for checking mod rewrite rules at http://htaccess.madewithlove.be/

Alternatively, if you have access to your servers zone file you could set up CNAME records for all domains that you want to point to the beta subdomain and no redirect would occur so that if a user goes to www.example.com the URL remains the same when they are in fact on the beta site.

|improve this answer|||||
  • Adding another condition makes complete sense! Thanks for your help! – Brandon Jul 11 '13 at 4:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.