Simple mod_rewrite issue in Fat Free Framework

I am trying to configure and learn Fat Free Framework for PHP. http://fatfree.sourceforge.net/

It is quite simple to configure, and I run it on my machine using MAMP.

I managed to get an example of "hello world" running only fin:

require_once 'path/to/F3.php'; F3::route('GET /','home'); function home() { echo 'Hello, world!'; } F3::run(); 

But when I try to add to 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 404 error if I try the second URL: / about

Not sure why one of the mod_rewrite commands will work, 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> 
+6
php .htaccess mod-rewrite fat-free-framework
source share
7 answers

So my friend really helped me deal with this problem. I ran into the same problem, but mostly I also use MAMP and have all my Fat Free files in the fatfree directory inside htdocs MAMP.

Solution: you need to change RewriteBase to /[dirname]/ instead of / , and then change RewriteRule to /[dirname]/index.php .

My .htaccess looks like this:

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

After this set, you can follow the example in the Fat Free document exactly and it will work like a charm. This prompted me for a while, and all this was necessary. Also, if you use MAMP, edit the httpd.conf file in /Applications/MAMP/conf/apache and remember to change the following:

 <Directory /> Options Indexes FollowSymLinks AllowOverride None </Directory> 

to

 <Directory /> Options Indexes FollowSymLinks AllowOverride All </Directory> 

Basically change None to All .

+11
source share

If you use F3 under a subfolder, you must change the RewriteBase in .htaccess to match the folder.

+2
source share

In your .htaccess you have "index.php", it needs a slash ... '/index.php'

 # 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] 

otherwise, when he tries to rewrite / about it, he will look for /about/index.php instead of the root /index.php


I just had a different thought. It is "possible" that although mod_rewrite is intalled, a quirk may occur with the server, causing it not to overwrite.

If the global route below does not work, you can test rewriting

 RewriteRule ^/google http://www.google.com [L,NC]; 

You can also try the global route for the directory.

 F3::route('GET /about/*','about'); 

but that means that any of them is in domain.com/about / ...... something ... will be redirected to the about function ...


Note on mod_rewrite and FF

As you said, FF sends you 404 because it expects '/' instead of '/index.php' ... However, it is index.php that expects the difference.

To demonstrate this, I believe that you can duplicate your

 F3::route('GET /','home'); 

as

 F3::route('GET /index.php','home'); 

and the page should be displayed ...

The reason for this is that you simply go to the / (or / index.php) directory via eitehr apache servex on the index.php page ....

mod_rewrite allows you to redirect / about and redirect it to index.php. So if your rewrite rule does not work, the redirect / rewrite will not happen and you will get 404 ...

As I mentioned above, test mod_rewrite with a Google rule .. then try going to http://localhost:80/google if it does not redirect you to Google then your rewrite mechanism does not work ... (maybe the window configuration problem .)


to enable mod_rewrite under windows: Open your http.conf Find this line:

 #LoadModule rewrite_module modules/mod_rewrite.so 

remove the comment mark (#) from the line ... so you have: LoadModule modules rewrite_module / mod_rewrite.so Save the file and restart apache.

Alternatively .. I think you can just say:

 LoadModule rewrite_module modules/mod_rewrite.so 

at the beginning of your htaccess file ...

+1
source share

I hit my head about it for 2 days. I debugged htaccess and php both. The actual problem is as follows:

If you copied the .htaccess file from their downloadable zip file without fat, then its .htaccess, its htaccess (.) Is missing. Just rename this file to .htaccess from htaccess and everything will work fine, as indicated in the document.

I use this .htaccess also works for root folders.

 Options -Indexes IndexIgnore * RewriteEngine On RewriteCond $1 !^(index\.php|images|main\.css|form\.css|favicon\.ico|robots\.txt|sitemap\.xml) RewriteRule ^(.*)$ index.php/$1 [L,QSA] 
+1
source share

Note. If you want to call the .htaccess file, you can change the file name using the AccessFileName directive. For example, if you prefer to call the .config file, you can put the following in the server configuration file:

 AccessFileName .config 

here

+1
source share

This answer may be too late for you, but yesterday I had the same problem.

The problem seems to be that apache is not rewriting the urls. I had the same problem when I try to run F3 on OSX 10.7 - the " GET / " route will work, but not " GET /foo ", since F3 index.php is in a subdirectory for localhost / F3. My solution was:

  • make sure .htaccess is installed as is.
  • ensure that mod_rewrite.so is included in apache httpd.conf
  • make sure you set AllowOverride All (mine was None) for your web directory in httpd.conf (hereinafter in the file).
  • restart apache

Without step 3, apache ignores any rewrite directives. I found this by changing permalinks to a local installation of Wordpress, and they did not indicate that the problem was with the apache configuration, not with F3.

0
source share

I run this using the MAMP stack. I renamed their folder from "fatfree-master" to "f3". I put this folder next to htdocs. Their .htaccess file (now inside MAMP / f3 / lib) remains untouched.

My .htaccess (in my web subfolder) is the stock standard according to their example:

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

Hope this helps someone.

0
source share

All Articles