简体   繁体   English

Symfony2:如何在子目录中部署(Apache)

[英]Symfony2: How to deploy in subdirectory (Apache)

What is the best way to deploy symfony2 application in a subdirectory or an alias ? 在子目录或别名中部署symfony2应用程序的最佳方法是什么?

Lets say that my application will run under: http://domain/symfonytest 让我们说我的应用程序将运行在: http://domain/symfonytest

symfonytest is an alias to some directory in my filesystem. symfonytest是我的文件系统中某个目录的别名。

Is there some CLI operation that I can use ? 我可以使用一些CLI操作吗?

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 回复到http://domain/symfonytest/demo被路由器视为/symfonytest/demo

Is there a way to tell router to ignore /symfonytest prefix for the whole application ? 有没有办法告诉路由器忽略整个应用程序的/symfonytest前缀?

If you are using Symfony < 2.3 you could follow this approach: 如果您使用Symfony <2.3,您可以遵循以下方法:

Just add RewriteBase in your .htaccess: 只需在.htaccess中添加RewriteBase

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /symfonytest
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ app.php [QSA,L]
</IfModule>

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): 在那之后你把控制器放在这样的东西(路径将是domain / symfonytest):

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

Path: domain/symfonytest/demo 路径:domain / symfonytest / demo

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

Hoep that helps Hoep有帮助

对于symfony3,它使用apache配置中的别名:

Alias /myapp /home/httpd/myapp/web

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM