1

I have multiple Symfony projects, each of them are stored in custom subdirs inside /srv/http; these subdirs are not intended to be public URLs. For example:

/srv/http/some/dir/sfprojA
/srv/http/some/other/dir/sfprojB
...

Note: I only have a personnal IP address, without any registered domain, and I'm using Apache 2.4.

I would like to link each of these projects to a simple URL (one per site), with a transparent rewrite for the final user. For example, http://my_ip/siteA would link to the sfprojA default route, http://my_ip/siteA/css/mystyle.css would link to the given stylesheet, etc...

For the moment, the only way I manage to handle multiple Symfony sites is to use the Apache virtual hosts feature:

Listen 10000
Listen 10001 https

<Location /siteA>
    Redirect http://my_ip:10000
</Location>

<VirtualHost *:10000>
    DocumentRoot /srv/http/some/dir/sfprojA/web

    <Directory /srv/http/some/dir/sfprojA/web>
        <IfModule mod_rewrite.c>
            Options -MultiViews
            RewriteEngine On
            RewriteCond %{REQUEST_FILENAME} !-f
            RewriteRule ^(.*)$ app.php [QSA,L]
        </IfModule>
    </Directory>
</VirtualHost>

<VirtualHost *:10001>
    DocumentRoot /srv/http/some/dir/sfprojA/web

    SSLEngine on
    SSLCertificateFile "/etc/httpd/conf/ssl/mycert.crt"
    SSLCertificateKeyFile "/etc/httpd/conf/ssl/mycert.key"

    <Directory /srv/http/some/dir/sfprojA/web>
        <IfModule mod_rewrite.c>
            Options -MultiViews
            RewriteEngine On
            RewriteCond %{REQUEST_FILENAME} !-f
            RewriteRule ^(.*)$ app.php [QSA,L]
        </IfModule>
    </Directory>
</VirtualHost>

It's working (assuming that the project was configured to handle https with port 10001), but there are several big problems:

  • Because /siteA is a redirection, the final user sees URLs like http://my_ip:10000/... instead of http://my_ip/siteA/...
  • It constrains me to open one port (or two ports with https) for EACH project I want to make public. And the routing configuration is not flexible at all, because I have to go each time to the web portal of my ISP in order to change anything.

How can I remove these problems by changing the Apache configuration?

yolenoyer
  • 123
  • 6

1 Answers1

0

Forgot all this vhost stuff. All you really need to do is to set Aliases in your main vhost:

Alias  "/siteA" "/srv/http/some/dir/sfprojA" 
Alias  "/siteB" "/srv/http/some/other/dir/sfprojB" 

See https://httpd.apache.org/docs/2.4/urlmapping.html

Sven
  • 97,248
  • 13
  • 177
  • 225
  • 1
    Actually, it doesn't work, because Symfony routes need to be passed through `web/app.php`. I will edit my question later – yolenoyer Mar 18 '17 at 15:56