Forum Moderators: phranque

Message Too Old, No Replies

Redirect match

Redirect old site to new site including subdomains

         

scraulb

3:29 pm on Apr 16, 2007 (gmt 0)

10+ Year Member



I have looked everywhere on this forum but I cannot figure out how to redirect 301 my whole site to a new one including subdomains.

So from www.oldsite.com to www.newsite.com
from sub1.oldsite.com to sub1.newsite.com
from sub2.oldsite.com to sub2.newsite.com
etc.

Is there a way to do this in a couple of lines?

I have tried variations on:

<VirtualHost 192.168.0.50:80>
ServerName www.oldsite.com
ServerAlias *.oldsite.com
RedirectPermanent / [newsite.com...]
</VirtualHost>

but no luck.

Any help would be greatly appreciated.

jdMorgan

4:31 pm on Apr 16, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



In order to preserve the subdomain (if present), you'll need to use mod_rewrite.

In httpd.conf or conf.d:


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

For more information, see the documents cited in our forum charter [webmasterworld.com] and the tutorials in the Apache forum section of the WebmasterWorld library [webmasterworld.com].

Jim

scraulb

4:45 pm on Apr 16, 2007 (gmt 0)

10+ Year Member



Thanks Jim. It worked like a charm!