0

I have a very legacy php application, that I'm trying to update to Symfony.

The application currently has a structure similar to this:

/www                        <-current web root
php_page1.php
php_page2.php
php_pagen.php
    /dashboard
    dashboard_page1.php
    dashboard_page2.php
    dashboard_pagen.php

The pages have helper files full of functions and the like, and there's also a few folders full of assets, but that's not really important. So to access a given page you'd point your browser to domain.com/php_page1.php or domain.com/dashboard/dashboard_page1.php... there's no front controller. All pages are accessed directly.

All in all, there's too much to refactor at once, so I want to do it in peices, one page at a time.

What I want to do is install symfony on top of what I have now, so the symfony structure will co-exist with what's currently here:

/www                        <-legacy
php_page1.php               <-legacy
php_page2.php               <-legacy
php_pagen.php               <-legacy
    /app                    <-symfony
    /dashboard              <-legacy
        dashboard_page1.php <-legacy
        dashboard_page2.php <-legacy
        dashboard_pagen.php <-legacy
    /src                    <-symfony
    /web                    <-symfony (new web root)
        .htaccess           <-symfony (points to app.php)
        app.php             <-symfony (front controller)

I've successfully installed Symfony and migrated a sample legacy page over (Please note the web root moved). This works great.

The trouble is, ultimately, I need Apache to serve the legacy pages if they exist, and go through front controller (app.php) if they do not.

Here's what I've tried.

I've tried various .htaccess rules to try and make Apache serve files in /www and /www/dashboard. These fail, with Symfony telling me there's no route to match to.

I've also tried Symfony's $this->redirect('..\www\php_page1.php');. This fails with Symfony telling me "Looks like you tried to load a template outside of configured directories."

Finally I tried to add /dashboard as a route:

/**
 * @Route("/cvdashboard/{file}")
 */
public function cvdashboardAction($file)  {
    return $this->render("@dashboard/$file");
}

And added a twig path:

twig:
    ...
    paths:
      '%%kernel.root_dir%/../dashboard':dashboard

This yealds three exceptions:

FileLoaderLoadException in FileLoader.php line 118:

InvalidArgumentException in YamlFileLoader.php line 371:

ParseException in Inline.php line 108:

Question

So my question is: How can I configure Symfony / Apache such that if a url that currently exists is called (i.e. domain.com/php_page1.php) it will serve that page either through Symfony or Apache directly and if it does not exist, have Symfony's front controller handle the request?

EDIT

Here's the .htaccess I currently have:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . app_dev.php [L]

This works for Symfony and routes anything I have a defined route for. The problem is that it's in /www/web (new web root), which is where Symfony wants the web root to be. It won't access anything in /www or /www/dashboard, which is outside the web root.

I'm trying to use .htaccess to either cause Apache to grab files from one level down from the web root, or cause Symfony to serve those pages as the generic php scripts they are.

mcmurphy
  • 781
  • 16
  • 30

1 Answers1

0

You can use mod_rewrite for that:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d # not an existing dir
RewriteCond %{REQUEST_FILENAME} !-f # not an existing file

# redirect to the symfony app.php file
RewriteRule ^(.*)$ www/app.php [L]
Dekel
  • 60,707
  • 10
  • 101
  • 129
  • thanks for the reply. I'm actually already using a very similar .htaccess file. The problem is it's in /www/web. I need to serve plain old php scripts from /www and /www/dashboard. – mcmurphy Dec 02 '16 at 01:07
  • You can use different `.htaccess` files for the `www` directory and the `www/web` directory. – Dekel Dec 02 '16 at 01:21
  • Would I also need to point the webroot to /www in order for that to work? – mcmurphy Dec 02 '16 at 01:23
  • i'm not sure if it's required, but i'm guess not. – Dekel Dec 02 '16 at 01:24