skip to Main Content

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


    1. my application in a subdirectory on apache server under /~test/

    2. the test was an example by test i actually meant ~username

    3. the homepage would be uni.co.uk/~myusername/index.php

    Put this on your application root directory’s .htaccess:

    <IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteRule ^$ /public/index.php [L]
    </IfModule>
    
    Login or Signup to reply.
  1. 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:

    controllers:
        resource: ../src/Controller/
        type: annotation
        prefix: /cool-prefix
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search