Basic Routing example 404 error

Help
2011-12-26
2012-09-25
  • Noel da Costa

    Noel da Costa - 2011-12-26

    I've not been able to get a simple routing example working in FatFree.

    This works (url: http://localhost/path/to/my/app/mycontroller/):

    F3::route('GET /','home');
    
        function home() {
            echo 'Hello, world!';
        }
    

    This doesn't (url: http://localhost/path/to/my/app/mycontroller/home):

    F3::route('GET /home','home');
        function home() {
            echo 'Hello World!';
        }
    

    Nor does this (url: http://localhost/path/to/my/app/mycontroller/about):

    F3::route('GET /about','about');
        function about() {
            echo 'Donations go to a local charity... us!';
        }
    

    Here's my .htaccess:

    # Enable rewrite engine and route requests to framework
    RewriteEngine On
    RewriteBase /path/to/my/app/
    RewriteCond %{REQUEST_FILENAME} !-l
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule .* /path/to/my/app/index.php [L,QSA]
    
    # Disable ETags
    <IfModule mod_headers.c>
        Header Unset ETag
        FileETag none
    </IfModule>
    
    # Default expires header if none specified (stay in browser cache for 7 days)
    <IfModule mod_expires.c>
        ExpiresActive On
        ExpiresDefault A604800
    </IfModule>
    

    Here's my folder structure:

    /path/to/my/app/mycontroller/index.php
    

    I've put my actions into that index.php file.

    I've tried everything I can think of. Mod_rewrite is enabled and working. I've
    checked Override All in the httpd conf and I've adjusted for paths in the
    .htacess file. I can even tell that my URL to "about" is getting to the main
    index.php file, but all I get is a 404 error.

    Thanks,
    geoidesic

     
  • Sn0opy

    Sn0opy - 2011-12-26

    First just try to remove the non-rewrite commands from your .htaccess file.
    Second, please change your RewriteRule to: ".* index.php ".

    I'm not sure whether this will work or not.

     
  • Bong Cosca

    Bong Cosca - 2011-12-26

    If /path/to/my/app/index.php contains all the route definitions, you shouldn't
    have any real file named /path/to/my/app/mycontroller/index.php. /home and
    /about are virtual paths, and that's what the Apache directive RewriteCond
    %{REQUEST_FILENAME} !-f describes. Delete
    /path/to/my/app/mycontroller/index.php and simply invoke the URLs
    http://localhost/path/to/my/app/home
    and http://localhost/path/to/my/app/about. It shouldn't be more complicated than that.

     
  • Noel da Costa

    Noel da Costa - 2011-12-27

    Thanks bcosca, but then where do I put my code for those actions if not in
    that "real file"??

     
  • Noel da Costa

    Noel da Costa - 2011-12-27

    This is what is not clear - what file must I put this code into:

    F3::route('GET /about','about');
        function about() {
            echo 'Donations go to a local charity... us!';
        }
    
     
  • Bong Cosca

    Bong Cosca - 2011-12-27

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

    routes to the about() function you defined above.

    F3::route('GET /about','mycontroller->about');
    

    routes to /path/to/my/app/mycontroller.php containing the mycontroller class
    and the about() action/method.

     

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks