Search code examples
phpapache.htaccessfuelphpfuelphp-routing

Public and Fuel folder in the same subdirectory, but no public/ in the URL


After reading over and over again the Installation Instructions for Fuel PHP (which I'm loving), I can't figure out how to make the app work without the url showing public/, and without moving the fuel folder from the docroot. (so it's all sefl-contained).

My setup is this:

/Users/AeroCross/Sites (this is where MAMP is loading all the files, i.e localhost) /Users/AeroCross/Sites/projects/mariocuba (this is the webroot of the Fuel app)

That contains:

    mariocuba/
        .htaccess
        oil
        fuel/
            app/
            core/
            packages/
        public/
            .htaccess

The .htaccess inside the mariocuba folder:

<IfModule mod_rewrite.c>
RewriteEngine on

RewriteBase /public

RewriteRule ^(/)?$ index.php/$1 [L]

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

RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

The .htaccess inside the public folder:

<IfModule mod_rewrite.c>
RewriteEngine on

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

RewriteRule ^(.*)$ index.php/$1 [L]

If I try to load the app (/Users/AeroCross/Sites/projects/mariocuba/), this error appears:

Not found.
The requested URL /public/index.php/ was not found on this server.

I don't know what to do in here.

I know that's not designed to work that way, and I know that's insecure, but this is for developing and version control purposes. What can I do (with minimal tweaking of the file system) to make this work?

It's worth noting that I have my config.php file configured with a base_url = null and index_file = null.

Any help appreciated!


Solution

  • Delete your existing .htaccess file from /mariocuba, move the contents of /mariocuba/public (including .htaccess) into /mariocuba and then edit index.php.

    Change:

    /**
     * Path to the application directory.
     */
    define('APPPATH', realpath(__DIR__.'/../fuel/app/').DIRECTORY_SEPARATOR);
    
    /**
     * Path to the default packages directory.
     */
    define('PKGPATH', realpath(__DIR__.'/../fuel/packages/').DIRECTORY_SEPARATOR);
    
    /**
     * The path to the framework core.
     */
    define('COREPATH', realpath(__DIR__.'/../fuel/core/').DIRECTORY_SEPARATOR);
    

    To:

    /**
     * Path to the application directory.
     */
    define('APPPATH', realpath(__DIR__.'/fuel/app/').DIRECTORY_SEPARATOR);
    
    /**
     * Path to the default packages directory.
     */
    define('PKGPATH', realpath(__DIR__.'/fuel/packages/').DIRECTORY_SEPARATOR);
    
    /**
     * The path to the framework core.
     */
    define('COREPATH', realpath(__DIR__.'/fuel/core/').DIRECTORY_SEPARATOR);
    

    This is detailed in the install instructions here: http://docs.fuelphp.com/installation/instructions.html#/manual