1

Apache is ignoring ServerName and ServerAlias for my main VirtualHost entry.

My scenario:

- main domain is "one.com" (just an example)
- secondary domains are several, pointing to the same IP of "one.com", but they need
to be in a different VirtualHost entry, so I can redirect to "one.com" using PHP
(I want to log redirects).

So, I did:

<VirtualHost 208.1.2.3:80>
    DocumentRoot /sites/redir
    ErrorLog logs/redir-error_log
    CustomLog logs/redir-access_log common
    ErrorDocument 404 /index.php
</VirtualHost>

<VirtualHost 208.1.2.3:80>
    DocumentRoot /sites/main
    ServerName one.com
    ServerAlias www.one.com
    DirectoryIndex index.html index.php
    ErrorLog logs/main-error_log
    CustomLog logs/main-access_log common
</VirtualHost>

Due to precedence, any domain different of one.com will use the first entry, that does not have ServerName nor ServerAlias.

The problem: ALL requests go to the first entry, including one.com and www.one.com what causes an infinite loop, since my PHP script redirects to one.com. If I invert the blocks, all requests go to the "main" entry...

What I need is that one.com and www.one.com runs in /sites/main and any other domain goes to /sites/redir to be redirected to the "one.com" entry.

Any ideas?

Thank you. Arvy

4

1 に答える 1