The MU forums have moved to WordPress.org

[Contrib] How-TO Use rewrite to handle multiple Domain Names (2 posts)

  1. DarkPepe
    Member
    Posted 16 years ago #

    [NOTE: This was designed for subdomain instalations]

    Hi, I'm currently using 2 domains on my MU instalation:

    http://losblogs.cl

    and

    http://losblogs.net

    I started using first the .CL domain and after a couple of months, I switch the complete instalation to the .NET domain.

    The Problem was, I need the old .CL URLS to resolve on the .NET adress for traffic, RSS and other related stuf.

    I found a preatty clever way to manage this situation using apache2 mod_rewrite.

    How To:

    The situation is the Following

    Main Domian: MAIN.NET
    Secondary Domain (It Will redirect to Main): Secondary.COM

    Virtual Host file for Secondary.COM

    
    <VirtualHost Secondary.COM>
    
    DocumentRoot /home/foo/bar
    DirectoryIndex index.php index.htm
    ServerName Secondary.COM
    ServerAlias http://www.Secondary.COM
    RedirectMatch (.*)$ http://MAIN.NET$1
    RedirectMatch (.*)/$ http://MAIN.NET$1
    RedirectMatch (.*).php$ http://MAIN.NET$1.php
    
    <Directory "/home/foo/bar">
    
    Options +FollowSymLinks
    AllowOverride All
    allow from all
    RewriteEngine On
    RewriteCond %{REQUEST_METHOD} ^(TRACE|TRACK)
    RewriteRule .* - [F]
    RewriteRule !^(..*|/)$ %{REQUEST_URI}/ [R=301,L]
    
    </Directory>
       </VirtualHost>

    This will redirect all the requests to Secondary.com to Main.NET, for example:

    http://exampleblog.secondary.com/wp-admin/index.php

    Will change to:

    http://exampleblog.MAIN.NET/wp-admin/index.php

    You can test it on my domains:

    Main: http://losblogs.NET
    Secondary (redirecting): http://losblogs.CL

    http://losblogs.cl/blog/2007/04/20/gom-player-alternativa-gratis-para-ver-dvds/

    It will redirect to:

    http://losblogs.net/blog/2007/04/20/gom-player-alternativa-gratis-para-ver-dvds/

    other example:

    http://thedigitalman.losblogs.cl/2005/04/

    Will redirect to:

    http://thedigitalman.losblogs.NET/2005/04/

    I hope this can help those ppl who has a 2 or more domains for their MU instalation.

    Cheers

    PD: You can check the full Virtualhost file on txt format here:

    http://losblogs.net/images/rewrite_url.txt

  2. andorko
    Member
    Posted 16 years ago #

    This might be simpler

    ServerName http://www.main.com
    ServerAlias main.com http://www.secondary.com secondary.com
    
    Options +FollowSymLinks
    RewriteEngine On
    
    RewriteCond %{HTTP_HOST}   !^www.main.com [NC]
    RewriteCond %{HTTP_HOST}   !^$
    RewriteRule ^/(.*)         http://www.main.com/$1 [R=301,L]
    

About this Topic

  • Started 16 years ago by DarkPepe
  • Latest reply from andorko