Reputation: 2032
Is it possible to deploy a Symfony2 project on the root dir (www.domain.com) and another Symfony2 project on a subdirectory? (www.domain.com/project2)
I see several questions and turorials about deploying a Symfony2 project on a subdirectory, but not on the root at the same time.
I have shared webhosting that uses an Apache webserver and have SSH access and can edit the .htaccess file, but I can't edit the httpd.conf file.
How would this be possible?
Edit: Instead of a subdirectory I created a subdomain in cPanel and installed a separate Symfony project there. Which works perfectly without changing the htaccess or other configuration.
Upvotes: 0
Views: 1216
Reputation: 2873
Anything is possible, but this will require some magic.
The problem is in .htaccess and more specifically in the rules Symfony2 puts there:
# If the requested filename exists, simply serve it.
# We only want to let Apache serve files and not directories.
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .? - [L]
# Rewrite all other queries to the front controller.
RewriteRule .? %{ENV:BASE}/app.php [L]
Your request to your subdirectory project will be re-written to the front controller of the main project, game over.
There are several ways to solve this. One would be to change the .htaccess file of the main project to explicitly exclude the subproject directory. However, due to the first rule this would still allow subproject files to be served from the main project which you may not want. That can be fixed with more fiddling with the rewrite rules.
The other option would be to use Symfony2 to solve this. I have a similar project (not quite your question, but also with subprojects), and my routing.yml is like this:
collaboration:
resource: "@CCollabBundle/Controller"
type: annotation
prefix: /{_site}
defaults:
_site: demo
You could simply add a routing rule without a prefix that points to your main project, and a routing rule with prefix that points to your subproject. For example (untested code, may or may not work):
mainproject:
resource: "@MainProjectBundle/Resources/config/routing.yml"
prefix: /
subproject:
resource: "@SubProjectBundle/Resources/config/routing.yml"
prefix: /subproject
Upvotes: 2