Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Since we have multiple apps on the same site (and all apps related to a big project), I place multiple apps inside the web folder like this:

web /

|-- frontend

|-- backend

|-- api

Each should have its own app.php and app_dev.php. It is possible to place the frontend's app.php and app_dev.php right under root but that kinda breaks the nice structure we are trying to keep.

I'm trying to use these rules in my .htaccess

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^app_dev\.php.*$ frontend/app_dev.php [QSA,L]

RewriteRule ^(.*)$ frontend/app_dev.php [QSA,L]

Seems to work fine, except the fact that all links generated now have the prefix 'frontend' like this: abc.com/frontend/usual-route

Is there anyway to tell Symfony to ignore the frontend part in this case?

share|improve this question
1  
Why don't you simply use routes pointing to different controllers depending on your application? I mean, that's what they're here for. –  nietonfir Oct 25 '13 at 20:45
add comment

1 Answer

you need to override the router's request context base url.

Add this to your app/config/paramters.yml:

parameters:
   router.request_context.base_url: /

See the documentation chapter Configuring the Request Context Globally.

Please note that you need a symfony version >= 2.2.0 to use this feature.

share|improve this answer
 
thank you very much, that works. Amazingly easy once you know how. BTW, I wonder if you have experience with htaccess rule? In my question above, if I comment out the line "RewriteRule ^app_dev\.php.*$ frontend/app_dev.php [QSA,L]" then everything works just fine but otherwise the stylesheets inside frontend/ will not be loaded correctly. I'm putting that line there hoping to be able to access the app_dev.php via the link mysite.com/app_dev.php –  mr1031011 Oct 26 '13 at 1:58
 
I would recommend you not to use the app_dev.php page on a publicly accessible domain as you will easily expose sensible information like container parameters. Better use environment variables to switch between environments in your app.php. As you're using Apache there is SetEnvIf ... So you could let Apache set the environment variable (i.e. SYMFONY__DEV_MODE=true ) if a certain key/value pair in the request header is found. in your dev environment you can use SetEnv to have symfony always show in dev environment under a certain local domain. –  nifr Oct 26 '13 at 8:58
 
Thank you for your advice nifr. Actually app dev will be used only on the local env, and since everyone is already used to having that app_dev.php prefix in our local env I was just wondering if I could do the same while leaving the real file in the sub folder. –  mr1031011 Oct 26 '13 at 11:08
 
Seem like 'RewriteRule ^app_dev\.php$ /frontend/app_dev.php [QSA,L]' works, but for some reason the routes generated on the site then all have the prefix /frontend/, even though router.request_context.base_url is set to '/'. Very weird. The normal, no app_dev.php links work fine tho. –  mr1031011 Oct 26 '13 at 19:22
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.