2

I want simple to rewrite everthing from OLD.COM to NEW.COM including subdomains and stuff - whatever user types in should just be replaced with NEW.COM and the rest of it stays as is. I tried this but it's not working for subdomains.

Options +FollowSymlinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^((www\.)?[^\.]+)\.old\.com [NC]
RewriteRule ^(.*)$ http://%1.new.com/$1 [R=301,L]

What did I miss? Thanks Bob

Bob
  • 21

1 Answers1

1

Delete all the subdomains in the apache config and replace it with this:

Listen *:80
<VirtualHost *:80>
    DocumentRoot /var/www/ #Wherever your site is located now
    ServerName olddomain.com
    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^(.*)olddomain\.com$ [NC]
    RewriteRule ^(.*)$ http://%1newdomain.com/$1 [R=301,L]
</VirtualHost>

That should redirect all subdomains.

Bart De Vos
  • 18,061
  • I tried it and this error comes up: "The server encountered an internal error or misconfiguration and was unable to complete your request." – Bob Apr 03 '11 at 18:51
  • Sorry, had a \ that wasn't supposed to be there. Does it work now? – Bart De Vos Apr 03 '11 at 18:53
  • still nothing happens if "WWW" is missing or by entering subdomains ( http://olddomain.com + http://subdomains.olddomain.com ) – Bob Apr 03 '11 at 19:24
  • Made some changes. Please try again. – Bart De Vos Apr 03 '11 at 20:17
  • only thing left is that subdomains aren't working are (like "http://anysubdomain.olddomain.com") - is it a server-based problem or can it be solved via .htaccess? – Bob Apr 03 '11 at 20:58
  • Where did you put the lines above? – Bart De Vos Apr 03 '11 at 21:25
  • I put the .htaccess in the root on my server. This is the complete code: Options +FollowSymlinks RewriteEngine on RewriteCond %{HTTP_HOST} ^(.*)olddomain\.com$ [NC] RewriteRule ^(.*)$ http://%1newdomain.com/$1 [R=301,L] – Bob Apr 03 '11 at 21:36
  • Aaah :-). You should put them in the general config-file for your old domain. Or create a catch-all if you don't have one. <VirtualHost *:80> You can only do this with a .htaccess file if you copy it to every subdomain. – Bart De Vos Apr 03 '11 at 21:47
  • btw: is there a chance to do it with Javascript if I put it into the index file or root? – Bob Apr 03 '11 at 22:49
  • No, The easiest method is to copy the same .htaccess file to every subdomain. The root of you site will not be loaded when you access it via a subdomain. Added some more information. – Bart De Vos Apr 04 '11 at 05:16