Multiple domains - one web server

Discussion in 'Apache' started by sudya, Apr 17, 2009.

  1. #1
    Here is the problem I have - there are a dozen (will be more) of domain names, let's call them
    mydomin1.com, mydomain2.com, ... mydomain12.com (the names will be absolutely different - no common pattern). The idea is to rewrite url based on the host name.
    I will set up folders accordingly, so we will have:
    /content/default/domain1.com
    /content/default/domain2.com
    ....
    /content/default/domain12.com

    DNS is set up to go to one web server, that web server has a default folder /content/default
    I also have .htacces in /content/default. Here is the code:
    RewriteEngine On
    RewriteBase /
    RewriteCond %{HTTP_HOST} (.*)$ [NC]
    RewriteCond %{REQUEST_URI} !^/%1/.*$
    RewriteRule ^(.*)$ /%1/$1 [L]
    
    Code (markup):
    So the idea is when user goes to http://mydomain1.com the url is rewritten to /content/default/domain1.com.

    The above example works if I will use the actual domain name instead of %1.

    Any suggestions how to fix that?
     
    sudya, Apr 17, 2009 IP
  2. hans

    hans Well-Known Member

    Messages:
    2,923
    Likes Received:
    126
    Best Answers:
    1
    Trophy Points:
    173
    #2
    what EXACTLY is the reason why you want to do simple things in a much complicated way ?
    I am sure you belief to have good reasons

    default apache usually is
    each domain has its own folder on server
    each domain has its own apache config file
    each domain has its own access configuration

    that allows individual modificat0ion and optimization as needed
    it also allows possible selling of site or designation of site-caretaker ( within own family for example )

    such simple default configuration WITHOUT rewriting sutff
    is covered entirely in the section
    apache2/vhosts.d
    of your apache configuration

    one day your sites or one of them gets grown up - has real traffic and
    needs own server for faster page loading
    having sites separately as done by default apache config gives later flexibility

    default apache configuration has a sever wide config file and a domain relevant config file or section to make things easier for YOU.
     
    hans, Apr 18, 2009 IP
  3. genius24k

    genius24k Active Member

    Messages:
    114
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    58
    #3
    Just use Virtual Host Feature of Apache, you don't need mod_rewrite for this.
     
    genius24k, Apr 28, 2009 IP
  4. SSANZ

    SSANZ Peon

    Messages:
    861
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Yeah i was going to say, wtf.. mod-rewrite for domains?

    Just use your control panel - addon domains...

    Or

    virtual host entries.
     
    SSANZ, May 2, 2009 IP