在所有控制器的symfony中更改baseURL

时间:2018-10-20 17:16:20

标签: apache symfony routing

因此,我将应用程序托管在/~test/下的apache服务器上的子目录中 我尝试在路由中添加前缀而没有任何反应

我希望所有控制器的所有路由都以/~test/开头,而无需手动将其添加到每个路由中。现在,当路线到达/到达我的/~test/目录之外

例如:

  /**
     * @Route("/login", name="app_login")
     */
    public function login(AuthenticationUtils $authenticationUtils): Response
    {
    }

我想去/~test/login的这条路线

我的.htaccess:

DirectoryIndex index.php

<IfModule mod_negotiation.c>
    Options -MultiViews
</IfModule>

<IfModule mod_rewrite.c>
    RewriteEngine On

    RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
    RewriteRule ^(.*) - [E=BASE:%1]

    RewriteCond %{HTTP:Authorization} .
    RewriteRule ^ - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    RewriteCond %{ENV:REDIRECT_STATUS} ^$
    RewriteRule ^index\.php(?:/(.*)|$) %{ENV:BASE}/$1 [R=301,L]

    RewriteCond %{REQUEST_FILENAME} -f
    RewriteRule ^ - [L]

    RewriteRule ^ %{ENV:BASE}/index.php [L]
</IfModule>

<IfModule !mod_rewrite.c>
    <IfModule mod_alias.c>
        RedirectMatch 307 ^/$ /index.php/
    </IfModule>
</IfModule>

2 个答案:

答案 0 :(得分:0)

  1.   

    我的应用程序在/〜test /

    下的apache服务器上的子目录中
  2.   

    测试只是一个测试示例,我实际上是指〜用户名

  3.   

    主页为uni.co.uk/~myusername/index.php

将其放在应用程序根目录的.htaccess上:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteRule ^$ /public/index.php [L]
</IfModule>

答案 1 :(得分:0)

看看那个https://symfony.com/blog/new-in-symfony-4-1-prefix-imported-route-names

您可以在routes.yaml文件中编写如下内容:

controllers:
    resource: ../src/Controller/
    type: annotation
    prefix: /cool-prefix