sleep
sleep

Reputation: 4954

Apache httpd.conf - Link multiple domains to corresponding subfolders

I need a rule to internally rewrite several domains, with and without www:

www.a.com --> /m/n/o/
b.c.org --> /x/y/z/

The setup is Apache running locally on Windows (XAMPP). I've got the hosts file set up so all the domains point to localhost. I'd like every page to get redirected, i.e. I want to point each domain to it's own different root directory and have it work normally from there. e.g.

/                          <-- Top level folder, everything is under here.
   /root/of/domain/A/      <-- www.a.com
   /root/of/domain/C/      <-- b.c.org

Upvotes: 0

Views: 100

Answers (1)

Justin Iurman
Justin Iurman

Reputation: 19016

You have two choices.

(1) The one you asked (with mod_rewrite)

<IfModule mod_rewrite.c>
  RewriteEngine On

  RewriteCond %{HTTP_HOST} ^(?:www\.)?a\.com$ [NC]
  RewriteRule ^/(.*)$ /root/of/domain/A/$1 [L]

  RewriteCond %{HTTP_HOST} ^b\.c\.org$ [NC]
  RewriteRule ^/(.*)$ /root/of/domain/C/$1 [L]
</IfModule>

Note: don't forget to replace example values by real ones. Also, make sure mod_rewrite is enabled.

(2) the cleanest way: configure virtualhosts directly (without mod_rewrite)

NameVirtualHost *:80

<VirtualHost *:80>
  DocumentRoot "X:/path/to/root/of/domain/A/"
  ServerName a.com
  ServerAlias www.a.com
</VirtualHost>

<VirtualHost *:80>
  DocumentRoot "X:/path/to/root/of/domain/C/"
  ServerName b.c.org
</VirtualHost>

Upvotes: 1

Related Questions