Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm installing a symfony project on /var/www/

And I have a special landing page stored here /var/www/web/landingpage

I want my visitors accessing http://www.mydomain.com to land on my landingpage and the ones accessing http://www.mydomain.com/foo to land on my symfony project.

I created 2 virtualhosts with different ServerPath and the landing page is working but not the symfony project.

Here is my conf:

<VirtualHost *:80>
    ServerAdmin admin@mydomain.com
    ServerName www.mydomain.com
    ServerPath /
    DocumentRoot /var/www/web/landingpage
    ErrorLog ${APACHE_LOG_DIR}/mydomain.com.error.log
</VirtualHost>


<VirtualHost *:80>
    ServerAdmin admin@mydomain.com
    ServerName www.mydomain.com
    ServerAlias mydomain.com sf.mydomain.com
    ServerPath /sf/

    DocumentRoot /var/www/web

    DirectoryIndex frontend.php

    <Directory /var/www/web>
            Order allow,deny
            Allow from all
            AllowOverride none

            <IfModule mod_rewrite.c>
                    RewriteEngine On

                    # we check if the .html version is here (caching)
                    RewriteRule ^$ index.html [QSA]
                    RewriteRule ^([^.]+)$ $1.html [QSA]
                    RewriteCond %{REQUEST_FILENAME} !-f

                    # no, so we redirect to our front web controller
                    RewriteRule ^(.*)$ frontend.php [QSA,L]
            </IfModule>
    </Directory>

    Alias /sf /var/www/lib/vendor/symfony/data/web/sf

    ErrorLog ${APACHE_LOG_DIR}/mydomain.sf.error.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn

    CustomLog ${APACHE_LOG_DIR}/mydomain.sf.access.log combined
</VirtualHost>

Note: my second Virtualhost without the first one and without ServerPath directive is working perfectly

share|improve this question
1  
With name based hosting, you should have only one virtual host entry for this hostname. Then you can handle it several ways. One solution would be to use an index page that forwards to the desired location. You could also accomplish with htaccess or mod_rewrite. But to start with, don't try to have 2 virtualhosts for the same hostname - combine into 1 and work from there. Or change your symphony project to use a subdomain such as foo.mydomain.com –  user16081 Feb 1 '13 at 19:08
    
I wish I could do this. But for marketing reasons (bags have been printed with mydomain.com/foo), I can't... And I can't change my symfony project as easy as I wish because 2 other languages (.fr and .de are working well like this :/) –  YoH Feb 2 '13 at 14:29
add comment

1 Answer 1

You cannot have two virtual host entries with the same hostname. That simply does not work.

Here's what you can do:

Change the second virtualhost to have

ServerName sf.domain.com

Leave everything else as it is in that second virtualhost.

In your first virtualhost, you add the following lines:

RewriteEngine On
RewriteRule ^/foo$ http://sf.domain.com [L,R]

Then, when anybody accesses www.mydomain.com/foo they will be redirected to sf.domain.com, the second virtualhost.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.