0

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 [email protected]
    ServerName www.mydomain.com
    ServerPath /
    DocumentRoot /var/www/web/landingpage
    ErrorLog ${APACHE_LOG_DIR}/mydomain.com.error.log
</VirtualHost>


<VirtualHost *:80>
    ServerAdmin [email protected]
    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

2
  • 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 Feb 1, 2013 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 :/) Feb 2, 2013 at 14:29

1 Answer 1

0

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .