So I’m hosting my application in a subdirectory on apache server under /~test/
I’ve tried adding prefix in routes with nothing happening
I want all routes of all my controllers to start with /~test/
without me adding that manually to each route. Right now when a route goes to / it goes outside of my /~test/
directory
for example:
/**
* @Route("/login", name="app_login")
*/
public function login(AuthenticationUtils $authenticationUtils): Response
{
}
This route I’d want to go to /~test/login
My .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
Answers
Put this on your application root directory’s
.htaccess
:Look at that https://symfony.com/blog/new-in-symfony-4-1-prefix-imported-route-names
You can write something like this in your routes.yaml file: