Search code examples
mod-rewriteapache2fat-free-framework

fat free php in subdirectory, routes not working


I'm staging a fatfree site, but I'm having an issue with it running in a subdirectory

this is my htaccess:

RewriteEngine On
RewriteBase /~site/
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* /~site/index.php [L,QSA]

and this is the route I'm using

GET /*/index=App->show_home

I'm having to add the /* before the rest of it, because the script keeps including the subfolder as part of the route.

this is working, I suppose, but once I update the dns settings, the site will no longer have these and I have to update it.

Is there a setting that I can apply somewhere that would allow both scenarios to work?


Solution

  • The basic required .htaccess goes like this:

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-l
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule .* index.php [L,QSA]
    

    Notice how:

    • RewriteBase is not needed
    • index.php is located in the same folder as .htaccess

    But when using mod_userdir, a little more configuration is required:

    1. Set RewriteBase explicitly (as you did): RewriteBase /~myuser/
    2. In the user directory Apache configuration, make sure that FollowSymlinks and AllowOverride All are enabled. They respectively allow the ~ link to be followed and .htaccess to be processed.

    Here's an example of a user directory Apache configuration:

    <Directory "/Users/myuser/Sites/">
        Options FollowSymlinks
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
    

    To answer your last question:

    Is there a setting that I can apply somewhere that would allow both scenarios to work?

    The answer is: no, as long as you're serving the website from a user directory. Move your website to the DocumentRoot and everything will run smoothly.