3

What is the best way to deploy symfony2 application in a subdirectory or an alias ?

Lets say that my application will run under: http://domain/symfonytest

symfonytest is an alias to some directory in my filesystem.

Is there some CLI operation that I can use ?

When I try to configure it manually I see a problem with routing.

Requets to http://domain/symfonytest/demo are seen by router as /symfonytest/demo

Is there a way to tell router to ignore /symfonytest prefix for the whole application ?

3 Answers 3

11

If you are using Symfony < 2.3 you could follow this approach:

Just add RewriteBase in your .htaccess:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /symfonytest
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ app.php [QSA,L]
</IfModule>
Sign up to request clarification or add additional context in comments.

10 Comments

Thanks, i forgot about RewriteBase :)
@lucian303 no need to downvote outdated info - many people are still on 2.0 or 2.1 and this can be helpful. It's not my fault that the question doesn't have the proper tag, and you can just edit the tags. For 2.3 you don't need to do anything, it seems to be supported out of the box.
@meze Sorry about that. You're right. Unfortunately, it isn't supported out of the box for 2.3 either (except on paper). They tried hard but failed miserably.
@meze you could update the answer specifying which up to which version this is necessary.
according to github.com/symfony/symfony-standard/commits/master/web/… the htaccess in symfony-standard introduced base detection in Mar/Apr 2013.
|
6

If your project sits in a different directory what i would do is set all traffic to go into one file via rewrite rule:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php [QSA,L]

And then I would set route prefix to my controller by annotation:

# Index (main page)
_nameRouteIndex:
    resource:  "@MyBundle/Controller/IndexController.php"
    type: annotation
    prefix: /symfonytest

After that you put in your controller something like this (path would be domain/symfonytest):

/**
 * Home page
 *
 * @return Response
 *
 * @Route("/", name="_index")
 */
 public function indexAction()
 {
 }

Path: domain/symfonytest/demo

/**
 * Demo page
 *
 * @return Response
 *
 * @Route("/demo", name="_demo")
 */
 public function demoAction()
 {
 }

Hoep that helps

Comments

0

For symfony3 it works with an alias in the apache config:

Alias /myapp /home/httpd/myapp/web

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.