-1

I have this apache server configured in mydomain.com/applications and inside that folder I have

  • /project1/ - using silex
  • /project2/ - using symfony 4

The server uses mod_rewrite and mydomain.com is represented by /var/www/html which is mapped as DocumentRoot in apache configuration.

In my local environment, /project2/ is mapped as project2.test and routes made with annotations works very well.

However, when moving the project to a directory, its routes doesn't work (whether in production or local env).

I'm pretty sure the routes were created correctly, but I guess I'm missing some symfony configuration when using symfony inside a subfolder.

I also tried to use RewriteBase "/application/project2/" in my /project2/.htaccess but didn't work.

yivi
  • 42,438
  • 18
  • 116
  • 138
Ricardo Martins
  • 5,702
  • 3
  • 40
  • 59
  • Define "routes doesn't work", do they all throw 404 error ? What's the output of `php bin/console debug:router` ? – Faizan Akram Dar Jul 16 '20 at 23:56
  • Yes, @FaizanAkramDar. All routes return 404. All routes are displayed in `debug:router` same way as they are displayed in local/working environment. – Ricardo Martins Jul 17 '20 at 00:40
  • Another interesting thing I noticed when activating debug and analyzing the 404 page is that symfony says "No routes found for "/project2/myroute/" and in the debug:router the path is displayed only as "/myroute". I guess I'm missing something in the config to tell symfony that the "/project2" is part of the path. – Ricardo Martins Jul 17 '20 at 00:44
  • the problem is, that the "root" directory (in the view from the web server) is the `public` directory (and the contained `index.php`) and is not the symfony project root. If you have this clear separation you should be able to achieve this with apache config alone. there's other approaches, for example moving the public dir: https://stackoverflow.com/questions/31426989/how-can-i-deploy-symfony-in-a-subdirectory (it's for older symfony version) the new options are here: https://symfony.com/doc/current/configuration/override_dir_structure.html#override-the-public-directory – Jakumi Jul 17 '20 at 01:08
  • But we do have redirects in place in the root folder for that purpose (.htaccess). Otherwise the 404 I am getting would be from apache, and not from symfony, right? – Ricardo Martins Jul 17 '20 at 01:34
  • I believe there is some apache bundle for symfony, have you installed it? also, have you cleared the cache since moving symfony around? symfony/apache-pack (it's essentially empty, the magic flows because of a flex recipe, that will override the project's local .htaccess) – Jakumi Jul 17 '20 at 06:24

1 Answers1

0

I solved the issue by adding an AliasMatch in my site's conf, inside <VirtualHost> as follows:

AliasMatch "^/project2/(.*)" "/path/to/documentroot/project2/public/$1"

Alternatively I could use just Alias as follows (this was my final solution):

Alias "/project2" "path/to/documentroot/project2/public"

The /project1/ didn't need any change, as .htaccess does the work properly there.

A /project2/public/.htaccess was generated using composer require symfony/apache-pack.

Ricardo Martins
  • 5,702
  • 3
  • 40
  • 59