Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Special structure (Multi apps) with assets
  • Hello everyone ! (sorry for my English I'm french and I can make mistakes)
    For a special project I have to create a multi apps website but with only one vhost (company limitations). So I choose to modify the structure of fuel to create multiple app with one core and one package for all apps, I have this structure :

    assets
    core
    fuel
        apps
            login
            work
            domain
    package
    public
        login
        work
        domain
    vendor

    In each public/login, public/work and public/login I have index file of the app and assets folder, but I have a top level assets folder in site root that is supposed to be shared between all apps.

    So I create assets config for each apps, when I try to get assets from this assets folder, in the inspector I see that the asset (for example css) was found and added to the page, I can even see sources by showinf the source in browser. But CSS style are not applied to the page..

    here is the htaccess file in root folder :

    <IfModule mod_rewrite.c>
    RewriteEngine On
    Options +FollowSymLinks

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d

    # Add trailing slash after apps uri if no exists
    RewriteRule ^(.*)login$ /login/ [L,R=301]
    RewriteRule ^(.*)domain$ /domain/ [L,R=301]
    RewriteRule ^(.*)work$ /work/ [L,R=301]

    # Redirect to each apps
    RewriteRule ^login(.*)$ public/login/$1 [L]
    RewriteRule ^domain(.*)$ public/domain/$1 [L]
    RewriteRule ^work(.*)$ public/work/$1 [L]
    # Redirect in case of no application specified
    RewriteRule ^(.*)$ public/login/ [L]
    </IfModule>
    Thanks to all people who will think about my problem :)
  • Sorry for double post.
    After verifications, In browser, the html code of the page show that css are not found on the server.
    To get more precise, my assets config look like this :
    <?php

    return array(

    'paths' => array(
    '../../assets/',
    'assets/'
    ),

    'folders' => array(
    'css' => array(),
    'js' => array(),
    'img' => array(),
    ),

    /**
    * URL to your Fuel root. Typically this will be your base URL:
    *
    * \Config::get('base_url')
    *
    * These MUST include the trailing slash ('/')
    */
    'url' => \Config::get('base_url'),

    'add_mtime' => true,

    'indent_level' => 1,

    'indent_with' => "\t",

    'auto_render' => true,

    'fail_silently' => false,

    'always_resolve' => false,

    );

  • In a setup like this, you need:
    • to point the DocumentRoot of your vhost to ./public (so you remove "public" from the path). 
    • have a fuel index.php + htaccess in each public/<appname> folder
    • to remove any fuel related files from your docroot
    Fuel has been made to run without issues in subfolders of the document root, you don't need any changes to the htaccess file, and you only need to change the path constants in each of the index.php files.

    The only thing you may need in the docroot (i.e. the public folder) is a redirect in case the site root is requested, or anything needed to deal with other (non-fuel) apps in that vhost.

    If your hoster supplies a different directory as your docroot (some use f.e. public_html), use that as your public folder.

    If your hoster doesn't provide any option to have files outside the docroot, and you need to install it all inside the docroot, change hoster to someone who takes security more serious (and in case of an in-company service, complain with the security officer!).

    If you can't, won't, or get no response, you're stuck with having "/public/" in the path (maybe rename it to something more appropriate, like "apps" or so?), the rest of the story renames the same. In this case you may also need a rewrite rule to capture requests to "/public".
  • Hello Harro :) !
    Thanks for your indications ! I'm in a company with strict policy (but not in security apparently...) and request never get response or actions :/...

    But I manage to solve my problem with assets :D !
    In the asset config I put the base URL of the website instead of the base url of the apps, example :

    www.test.fr/login --> login app base url
    www.test/fr/       --> website base url

    After that I change assets folder config in apps and magic append !

    I follow your advice and I rename public folder to apps (SEO friendly and user friendly too) and I'm going to write htaccess that redirect all request to this folder (no for file and folder).

  • lol, these things happen.

    Good you've got it sorted, thanks for the feedback. As always, there are more solutions to fix a problem. ;-)
  • I have only one more problem ^^...
    I have trouble to create htaccess that redirect all requests to apps folder even if it should be simple >< !
    I have this set of rules that redirect each apps in the good folder and I try to manage other request to redirect to 404 page of login app :
    <IfModule mod_rewrite.c>
    RewriteEngine On

    RedirectMatch ^/$ /login/

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^login(.*)$ /apps/login/index.php/$1/ [L]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^work(.*)$ /apps/work/index.php/$1/ [L]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^domain(.*)$ /apps/domain/index.php/$1/ [L]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule $ /apps/login/index.php/404/ [L]
    </IfModule>
    I think that it's not the best solution :/... Have you any idea about this problem ?
  • HarroHarro
    Accepted Answer
    That doesn't work if "404" is not defined as a route, default error routes can't be called this way (this is done on purpose).

    RewriteRule $ /apps/login/index.php/controllermame/404/ [L]

    should work, providing Controllername has an action_404() method.

    Having said that, this should work fine too:

    RewriteRule $ /apps/login/index.php/somethingthatabsolutelydoesnotexist [L]

  • Ok I'm dumb sometimes ^^ !
    This issue is fixed but now assets folders in each apps does not work anymore while the global asset folder works perfectly, it is like I redirect assets too when they are in the apps/app folder :/
  • What asset url's are now generated, with your current config?
  • I manage to fixe the problem with the following htaccess :
    <IfModule mod_rewrite.c>
    Options +FollowSymLinks
    RewriteEngine On

    RedirectMatch ^/$ /login/

    RewriteRule ^(.*?)\.(php|css|js|jpg|jpeg|png|pdf)$ - [L,NC]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^login(.*)$ /apps/login/index.php/$1/ [L]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^work(.*)$ /apps/work/index.php/$1/ [L]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^domain(.*)$ /apps/domain/index.php/$1/ [L]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule $ /login/ [L,R=302]
    </IfModule>
    But now I have trouble to use multiple paths for assets, my configuration in each apps for assets paths is the following:
    'paths' => array(
    'assets/',
    'apps/login/assets/',
    ),
    But generated url use only the last path of the array even if the asset does not exist :/
    The generate url always take the following form :

    www.example.fr/apps/app/assets/css/style.css

    But never

    www.example.fr/assets/css/style.css

    Even if the file exists only in /assets/, generated url is the first and no error is thrown... :/
  • Ok I solve the last problem and now all work fine !
    To solve it I declare two instance of Asset in each app bootstrap file, one for global assets and one for local assets and it work like a charm ;) !

    Thanks a lot for your help Harro !

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion