5

Below is the directory structure of my fuelphp project

  • fuel
  • logs
  • public
  • tmp

In public folder i have

  • assets
  • index.php

When I hit any URL other than base URL it throws following error

Object not found error

here is my login code

public function action_index(){

    $html = new Template();

    if(Session::get("logged_in")){

      Response::redirect('/test-newsletter');

      exit(0);
    }
     // die("in ifss");
    if(Input::post()){

      $username = Input::post('username','');
      $password = Input::post('password','');

      if($username === "username" && $password === "password") {

        Session::set('logged_in', true);

        Response::redirect('/test-newsletter');

      }else{
        $html->assign('message','Wrong username or password');  
      }

    }

    return $html->fetch('login.tpl');

  }

here is my routes.php

<?php

return array(

  "_root_"  => "default/index", 
  "logout" => "default/logout",
    "_404_"   => "default/404",
  "time" => "default/time",  
  "test"  => "default/test",

  "birthdays" => "backstage/birthdays",
  "earned-status" => "backstage/earned_status",
  "nearly-new-status" => "backstage/nearly_new_status",
  "placed-order" => "backstage/placed_order",
  "user-history" => "backstage/user_history",
  "test-newsletter" => "backstage/test_newsletter",
  "preview-email" => "backstage/preview_email",

  "view-email/:id" => "backstage/view_email",

  "api/set-date" => "backstage/api_set_date"
);

this is the Backstage controller test_newsletter function

public function action_test_newsletter(){
    die("here");
    $submitted = Input::post("submit", false);
    $points = Input::post("points", "");
    $email = Input::post("email", "");
    $type = Input::post("type", "");

    $html = new Template();
    $html->assign("points", $points);
    $html->assign("email", $email);
    $html->assign("type", $type);
    $html->assign("message", "");

    if($submitted){
      $testService = new TestService(trim($type), trim($email), trim($points));

      if($testService->isValid()){
        $testService->processEmail();
        $html->assign("message", "Email Sent!");

      }else{
        $html->assign("message", $testService->getErrorMesssage());
      }
    }

    return $html->fetch("test_newsletter.tpl");
  }

But after login its not going to test_newsletter instead its showing me Object not found error.

** I have read that wee need to put .htaccess somewhere in our project but I am not clear about that. Can any guide me **

Awais Qarni
  • 17,492
  • 24
  • 75
  • 137
Mirza Obaid
  • 1,707
  • 3
  • 23
  • 35
  • 1
    Normally, the `.htaccess` file is placed in your `DOCUMENT_ROOT` path - in your case, this should be `public`. In order to verify that you, indeed, need an `.htaccess` try adding `index.php` to your path, like `index.php/test` or something else and see if you get an actual response this time. – Artamiel Sep 08 '17 at 10:58
  • @Artamiel I got same problem. I added .htaccess on root of my folder. I have created a virtual host (using xampp). No url other than main url is working. It is throwing error on all url. My mod_rewrite is on. And .htaccess looks like RewriteEngine on RewriteBase /web_manage/public RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(/)?$ index.php/$1 [L] RewriteRule ^(.*)$ index.php/$1 [L] – Awais Qarni Sep 08 '17 at 11:48
  • @AwaisQarni what version of FuelPHP are you running? I've just downloaded the last stable `1.8.0` and simply extracted the archive in my `www` with no further configuration. Simply loading `localhost/fuel/public/hello` (it's a default route) yielded a result for me. Download the source again and take a look at the `.htaccess` file the project ships with and give it another go. – Artamiel Sep 09 '17 at 08:15
  • FuelPHP comes with an .htaccess file that works fine, so if you have your own file, that is the obvious candidate. Especially if with "object not found" you mean the standard Apache 404 error. You can download the latest .htaccess here: https://raw.githubusercontent.com/fuel/fuel/1.9/develop/public/.htaccess – WanWizard Sep 12 '17 at 12:08

1 Answers1

0

Try this .htaccess in your web root folder (usually public/ ?):

RewriteEngine On

# The following rule tells Apache that if the requested filename
# exists, simply serve it.

RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]


# The following rewrites all other queries to index.php. The 
# condition ensures that if you are using Apache aliases to do
# mass virtual hosting, the base path will be prepended to 
# allow proper resolution of the index.php file; it will work
# in non-aliased environments as well, providing a safe, one-size 
# fits all solution.

RewriteCond %{REQUEST_URI}::$1 ^(/.+)(.+)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteRule ^(.*)$ %{ENV:BASE}index.php [NC,L]
delboy1978uk
  • 12,118
  • 2
  • 21
  • 39