mod_rewrite multiple domains one vhost

Discussion in 'Apache' started by tyrrvk, Apr 4, 2011.

  1. #1
    Hi -
    I have a single website call it PRIMARYSITE.NET
    This is being served as a vhost on my CentOS 5.5 server.

    This server has a single static IP address with a number of cnames associated with it.

    I want to take all the various cnames addresses and direct them to the website, using the above URL example (PRIMARYSITE.NET)
    So, I need www.primarysite.net rewritten to primarysite.net
    I need www.primarysite.COM rewritten to primarysite.net
    I need primarysite.COM rewritten to primarysite.net
    and I need oldsiteurl.net and www.oldsite.net rewritten to primarysite.net

    However, I cannot get these all working - and I suspect it's mainly due to vhost conf files. Some of the rewrites seem to work, but others don't. I don't know how to order/setup my virtual host file(s) or how to setup a "default" vhost conf file or modfiy the main httpd.conf file.

    1st question:
    do I need to setup different vhost conf files for each "site" or URL? I only have one website currently being served. I just have a bunch of old URLS that need to redirect properly. How do I write the vhost conf file so that it works for all the different URLS?
    The vhost file has "servername" field - primarysite.net. I can specify a serveralias of *.primarysite.net as well....but what about the other URLS I want to catch and then rewrite?


    2nd question:
    How do I create a rule that looks for www.primarysite.com or primarysite.com and rewrites it to primarysite.NET?

    My vhost.conf file has the following code:
    
    <IfModule mod_rewrite.c>
    
            # mod_rewrite
            RewriteEngine On
    
            RewriteCond %{HTTP_HOST} ^primarysite\.com$ [NC]
            RewriteRule ^/(.*) http://primarysite.net/$1 [L,R=301]
    
        </IfModule> 
    
    
    Code (markup):
     
    tyrrvk, Apr 4, 2011 IP