0

I hope that this question is not a duplicate, but I only found articles or questions about this for old versions of Symfony. I am new to Symfony 4 and I would like to create a new application with it and install it as a part of an already existing website (domain below). The Sf 4 app goes into the admin/ subdirectory shown in the hierarchy below. domain uses the TYPO3 CMS, but I’m not sure that it matters for this question.

First, here is the directory structure :

/home/webuser/domain/
    public/ (this is the document root for "domain.localhost")
        admin/ (the Symfony app goes here)
            public/
            …
        …
        typo3/
        .htaccess
        index.php
        …
        composer.json

I am currently working on the website on my local machine and I would like to access the Symfony application root from domain.localhost/admin. I am using an Apache virtual host and the domain/public folder is the document root of domain :

<VirtualHost *:80>
    ServerName domain.localhost
    DocumentRoot "/home/webuser/www/domain/public"
</VirtualHost>

I tried adding the following rewrite rule to my VirtualHost :

<VirtualHost *:80>
    ServerName domain.localhost
    DocumentRoot "/home/webuser/www/domain/public"
    RewriteEngine On
    RewriteRule "^/admin/(.*)$" "/admin/public/$1"
    LogLevel trace1
</VirtualHost>

But this seems to work only when I visit http://domain.localhost/admin/ : I then see the "Welcome to Symfony 4.2.7" page. As soon as I try to visit a subpage, I get a 404 error. I tried to create my first page at lucky/number as explained in the documentation here, and looking at the Apache error log, I have lines such as :

[Mon Apr 29 18:52:09.472043 2019] [rewrite:trace1] [pid 22250:tid 140404453660416] mod_rewrite.c(483): [client ::1:43084] ::1 - - [domain.localhost/sid#55a33c704bf8][rid#7fb260002bd0/initial] [perdir /home/webuser/www/domain/public/] pass through /home/webuser/www/domain/public/admin/public/lucky

[Mon Apr 29 18:52:09.472087 2019] [core:info] [pid 22250:tid 140404453660416] [client ::1:43084] AH00128: File does not exist: /home/webuser/www/domain/public/admin/public/lucky/number

Now, TYPO3 has an .htaccess file containing URL rewrites, but I don’t think that they are interfering. Below, I just added myself the admin/ folder in the rule after the comment that starts with "Stop rewrite processing", so that we are not redirected to the home page of the domain website when the file is not found :

<IfModule mod_rewrite.c>

    # Enable URL rewriting
    RewriteEngine On

    # Store the current location in an environment variable CWD to use
    # mod_rewrite in .htaccess files without knowing the RewriteBase
    RewriteCond $0#%{REQUEST_URI} ([^#]*)#(.*)\1$
    RewriteRule ^.*$ - [E=CWD:%2]

    # Rule for versioned static files, configured through:
    # - $GLOBALS['TYPO3_CONF_VARS']['BE']['versionNumberInFilename']
    # - $GLOBALS['TYPO3_CONF_VARS']['FE']['versionNumberInFilename']
    # IMPORTANT: This rule has to be the very first RewriteCond in order to work!
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.+)\.(\d+)\.(php|js|css|png|jpg|gif|gzip)$ %{ENV:CWD}$1.$3 [L]

    # Access block for folders
    RewriteRule _(?:recycler|temp)_/ - [F]
    RewriteRule fileadmin/templates/.*\.(?:txt|ts)$ - [F]
    RewriteRule ^(?:vendor|typo3_src|typo3temp/var) - [F]
    RewriteRule (?:typo3conf/ext|typo3/sysext|typo3/ext)/[^/]+/(?:Configuration|Resources/Private|Tests?|Documentation|docs?)/ - [F]

    # Block access to all hidden files and directories with the exception of
    # the visible content from within the `/.well-known/` hidden directory (RFC 5785).
    RewriteCond %{REQUEST_URI} "!(^|/)\.well-known/([^./]+./?)+$" [NC]
    RewriteCond %{SCRIPT_FILENAME} -d [OR]
    RewriteCond %{SCRIPT_FILENAME} -f
    RewriteRule (?:^|/)\. - [F]

    # Stop rewrite processing, if we are in the typo3/ directory or any other known directory
    # NOTE: Add your additional local storages here
    RewriteRule ^(?:typo3/|fileadmin/|typo3conf/|typo3temp/|uploads/|favicon\.ico|admin/) - [L]

    # If the file/symlink/directory does not exist => Redirect to index.php.
    # For httpd.conf, you need to prefix each '%{REQUEST_FILENAME}' with '%{DOCUMENT_ROOT}'.
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-l
    RewriteRule ^.*$ %{ENV:CWD}index.php [QSA,L]

</IfModule>

The production server will be a dedicated system, so I can modify anything I want.

user1738984
  • 564
  • 1
  • 4
  • 14

1 Answers1

1

It turns out that I just needed to install the Apache pack, like in this answer

user1738984
  • 564
  • 1
  • 4
  • 14