I am trying to setup and learn the Fat Free Framework for PHP. http://fatfree.sourceforge.net/
It's is fairly simple to setup and I am running it on my machine using MAMP.
I was able to get the 'hello world' example running just fin:
require_once 'path/to/F3.php';
F3::route('GET /','home');
function home() {
echo 'Hello, world!';
}
F3::run();
But when I try to add in the second part, which has two routes:
require_once 'F3/F3.php';
F3::route('GET /','home');
function home() {
echo 'Hello, world!';
}
F3::route('GET /about','about');
function about()
{
echo 'About Us.';
}
F3::run();
I get a 404 error if I try the second URL: /about
Not sure why one of the mod_rewrite
commands would be working and not the other.
Below is my .htaccess
file:
# Enable rewrite engine and route requests to framework
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php [L,QSA]
# Disable ETags
Header Unset ETag
FileETag none
# Default expires header if none specified (stay in browser cache for 7 days)
<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault A604800
</IfModule>
I'm running this with a MAMP stack. I renamed their folder from "fatfree-master" to "f3". I put that folder next to htdocs. Their .htaccess file (now inside MAMP/f3/lib) remains untouched.
My .htaccess (in my web subfolder) is stock standard as per their example:
Hope this helps someone.
I banged my head on this for 2 days. I debugged htaccess and php both. The actual problem is this :
If you copied the .htaccess file from their fatfree-1.4.4 zip download, its not .htaccess its htaccess (. is missing) Just rename this file to .htaccess from htaccess and everything will work perfectly as its mentioned in the document !!!
I am using this .htaccess works for non-root folders too
In your .htaccess you have 'index.php' it needs a slash ... '/index.php'
otherwise when it tries to rewrite /about/ it will look for /about/index.php instead of just the root /index.php
I just had another thought.. it 'is' possible that althought mod_rewrite is intalled there may be a quirk with the server causing it not to rewrite..
If the global route below doesnt work you might want to test the rewrite
You could also try a global route for the directory
but that means anythin under domain.com/about/ ...... anything ... will reroute to the about function...
A note about mod_rewrite and FF
As you said, FF is givikng you a 404 because it is expecting '/' instead of '/index.php'... However, it is the index.php which is expecting the difference..
To demonstrate that, i believe you can duplicate your
as
and the page should display...
The reason for this is if you just go to the / directory (or /index.php) eitehr way apache servesx the index.php page....
The mod_rewrite allows you to redirect the /about and have it redirect to the index.php.. So if your rewrite rule is not working then the redirect/rewrite does not happen and you will get a 404...
As i mentioned above, test the mod_rewrite with the google rule.. then try to go to
http://localhost:80/google
if it does not redirect you to google then your rewrite engine is not working... (probably an issue with the windows configuration..)to enable mod_rewrite under windows: Open your http.conf Find this line:
remove the comment mark (#) from the line... so you have: LoadModule rewrite_module modules/mod_rewrite.so Save the file and restart apache..
Alternatly.. I think you can just say:
at the start of your htaccess file...
So my friend actually helped me out with this issue. I ran into the exact same problem, but basically I'm using MAMP also and have all my Fat Free files within a
fatfree
dir within htdocs of MAMP.The solution is you need to mod the
RewriteBase
to point to/[dirname]/
instead of just/
and then changeRewriteRule
to/[dirname]/index.php
.My .htaccess looks like this:
After that's set, you can follow the example in the Fat Free doc exactly and it'll work like a charm. This stumped me for a while and this was all it needed. Also, if you're using MAMP, edit the
httpd.conf
file in/Applications/MAMP/conf/apache
and be sure to alter the following:to
Basically change
None
toAll
.If you're running F3 under a subfolder, you must change the RewriteBase in .htaccess to match the folder.
This response may be too late for you but I had the same problem yesterday.
It sounds like the problem is apache is not rewriting urls. I had the same issue when trying to get F3 running on OSX 10.7 - the '
GET /
' route would work but not the 'GET /foo
' as the F3 index.php was in a subdir for localhost/F3. My solution was to:AllowOverride
All
(mine was None) for your web directory in httpd.conf (further down the file).Without step 3, apache will ignore any rewrite directives. I discovered this by changing the permalinks on a local wordpress install and they failed indicating the problem was the apache config, not F3.