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
/siteAis a redirection, the final user sees URLs likehttp://my_ip:10000/...instead ofhttp://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?