Kohana 404 error: Requested URL not found - php

.
Hi everyone,
I'm working on a website for a school project.
Recently I've purchased me own webspace at Biberbit.com and wanted to upload my website.
When I upload it I see the following error on screen:
Kohana_HTTP_Exception [ 404 ]: The requested URL / was not found on this server.
My project uses the Kohana framework version 3.3.1
I already have the .htaccess file and the filenames/directory names are all lower case.
I am using the default route:
Route::set('default', '(<controller>(/<action>(/<id>)))')
->defaults(array(
'controller' => 'welcome',
'action' => 'index',
));
Originally I thought it might have been the default_url in the bootstrap.php file so I've changed those lines to this:
Kohana::init(array(
'base_url' => '/',
'index_file' => FALSE,
));
I've looked for the solution on multiple websites and couldn't find one that works for me.
Can anyone think of something that I might be missing?
I'm also using URL::site() for my links so I don't think that's causing it.
You can check the error and/or website at http://www.biberbit.com
EDIT:
.htaccess as requested
# Turn on URL rewriting
RewriteEngine On
# Installation directory
RewriteBase /
# Protect hidden files from being viewed
<Files .*>
Order Deny,Allow
Deny From All
</Files>
# Protect application and system files from being viewed
RewriteRule ^(?:application|modules|system)\b.* index.php/$0 [L]
# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Rewrite all other URLs to index.php/URL
RewriteRule .* index.php/$0 [PT]

The base_url is set wrong, it should be empty (as you are on the web root). Also depending on whether or not you have Linux, filenames must not be all lowercase but however you use them in the code. So Welcome.php and not welcome.php for the default controller.

Kohana_HTTP_Exception [ 404 ]: The requested URL / was not found on this server. exception is usually thrown when Kohana couldn't find corresponding action method to process a request.
Make sure you have Controller_Welcome class and action_index method in it.
Also you can inspect your Exception traceback and find what exactly caused an Exception. Most likely you'll see Exeption in SYSPATH/classes/Kohana/Controller.php file in if(!method_exists(...)) block.

Related

Assets found but not loaded after installing Laravel into a legacy project, possibly due to htaccess file not being loaded

I'm using this guide to install Laravel into a legacy application. I copied all legacy files into a single legacy directory, installed a new Laravel 8 project (server doesn't use PHP8 yet so can't use L9) and copied the legacy directory into the Laravel directory. I then followed the steps to make changes to the routes/web.php file, created the LegacyController and called the legacy application's index.php file.
web.php;
Route::any('{path}', LegacyController::class)->where('path', '.*');
LegacyController.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Response;
class LegacyController extends Controller
{
public function __invoke()
{
ob_start();
require app_path('Http') . '/legacy.php';
$output = ob_get_clean();
return new Response($output);
}
}
app\Http\legacy.php;
<?php
require __DIR__ . '/../../legacy/Website/index.php';
The legacy website uses a custom CMS which is loaded in its index.php file. In short, it parses the URL to get the slug, according to which it looks up if a page exists with that slug. If so it looks up the component belonging to the page (components are basic PHP files) and loads them using include_once. If a page isn't found, it redirects the user to /404.
There are some .htaccess rules to allow for "friendly" URLs etc;
# Enable the rewrite engine
RewriteEngine On
RewriteBase /website.tld
# SSL Redirect 301 transfer the current request.
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# never rewrite for existing files, and links
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -l
RewriteRule ^ - [L]
# For Friendly URLs
RewriteRule ^ index.php [L]
However this .htaccess file doesn't seem to be loaded at all, as existing files (for example, PDF files but also links to CSS and JS files) are all treated as having to be routed through the CMS and thus resulting in a redirect to the 404 page.
To test whether or not the .htaccess file is loaded I added
ErrorDocument 200 "Hello. This is your .htaccess file talking."
RewriteRule ^ - [L,R=200]
to the file as described here, and as expected nothing happens. When I add the same lines to Laravel's .htaccess file in the public directory, I do get the message.
There are some other issues with other existing CMS pages not being found, but I feel like this all happens because the .htaccess file is not being used.
How can I make sure the legacy application's .htaccess file is properly used by Laravel?

Not Found HTTP 404 (GET /) • C:/wamp/www/fatfree-master/index.php:111 Base->run()

I am trying to use the php fat free framework (aka F3), to quickly build a web application.
In theory (from reading the documentation), it should be a doddle (i.e. easy), however, I have been stuck on a single problem for days, and judging from similar questions here on stackoverflow, it seems I'm not the only one struggling with this issue.
Here are the salient facts:
I am using wamp server to run F3.
My F3 project resides under /location-to-wamp-folder/www/fatfree-master
I have setup a virtual host for Apache under wamp, so http://fatfree-master runs index.php
This is where the trouble begins. When I navigate to http/fatfree-master, I get the error which is the title of this question; namely:
Not Found
HTTP 404 (GET /) C:/wamp/www/fatfree-master/index.php:111 Base->run()
My index.php looks like this:
<?php // <- surprisingly, I had to add this line to the index.php example provided by F3, was this an oversight or a deliberate design feature?
$f3=require('lib/base.php');
$f3->set('DEBUG',3);
$f3->set('UI','ui/');
....
// custom PHP code defining routes etc ...
....
$f3->run(); // barfs here
Now, I would be the first to admit, that I do not understand the arcane syntax of Apache rewrites, so I have left my .htaccess file as it was (when I downloaded F3).
Here are the contents of my .htaccess (the default file provided by F3):
# Enable rewrite engine and route requests to framework
RewriteEngine On
# Some servers require you to specify the `RewriteBase` directive
# In such cases, it should be the path (relative to the document root)
# containing this .htaccess file
#
# RewriteBase /
RewriteRule ^(tmp)\/|\.ini$ - [R=404]
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php [L,QSA]
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
Can anyone explain to me, why I am getting the 404 error, and also how to fix it?
[[Additional Notes]]
I have two routes in my (edited) index.php file. My index.php looks like this now:
<?php
$f3=require('lib/base.php');
$f3->set('AUTOLOAD','app/controllers/');
$f3->set('DEBUG',3);
$f3->set('UI','ui/');
/* Tools */
$f3->route('GET #tools_calculator_dates: /tools/calculator/dates', 'Beer->list');
// Default route
$f3->route('GET /',
function() {
echo 'Hello, world!';
}
);
$f3->run();
When I access / in my browser, I get "Hello, world!" (as expected)
When I access /tools/calculator/dates in the browser, I get the following error:
Not Found
HTTP 404 (GET /tools/calculator/dates)
• C:/wamp/www/fatfree-master/index.php:119 Base->run()
Now, I have a class here: /path/to/wamp/www/fatfree-master/app/controllers/beer.php
The contents of the class are:
<?php_
class Beer
{
function list() {
echo "Beer::list() called!";
}
}
Why I am getting the 404 error?.
The error you're getting is not from Apache, it's from F3.
If you don't specify a route GET /, F3 will throw a 404.
The 404 error could be caused by one of the following reasons:
the route you're calling hasn't been defined
the class or method against which the route has been defined cannot be found
you're running the web app in a subfolder and for some reason, RewriteBase needs to be enabled
Concerning the point #1, see the documentation for details about route declaration.
Concerning the point #2, check out this answer if you're having trouble setting the framework's autoloader (AUTOLOAD variable).
Regarding the point #3: RewriteBase is usually optional when running in a subfolder, but in specific cases (for ex. when mod_userdir is enabled), it needs to be explicitly set.
So in your case, you could try to add the following directive in your .htaccess file, just after RewriteEngine On:
RewriteBase /fatfree-master/

Kohana URL not found

Hi i have a problem with my kohana code it's getting me the same error and i think there's a problem with the htaccess or bootstrap
It's installed on my root directory not as a subfolder.
Kohana_HTTP_Exception [ 404 ]: The requested URL / was not found on this server.
SYSPATH/classes/Kohana/Request/Client/Internal.php [ 79 ]
74 if ( ! class_exists($prefix.$controller))
75 {
76 throw HTTP_Exception::factory(404,
77 'The requested URL :uri was not found on this server.',
78 array(':uri' => $request->uri())
79 )->request($request);
80 }
81
82 // Load the controller using reflection
83 $class = new ReflectionClass($prefix.$controller);
84
SYSPATH/classes/Kohana/Request/Client.php [ 114 ] » Kohana_Request_Client_Internal->execute_request(arguments)
SYSPATH/classes/Kohana/Request.php [ 990 ] » Kohana_Request_Client->execute(arguments)
DOCROOT/index.php [ 109 ] » Kohana_Request->execute()
Here's my htaccess code
# Turn on URL rewriting
RewriteEngine On
# Installation directory
RewriteBase /
# Protect hidden files from being viewed
<Files .*>
Order Deny,Allow
Deny From All
</Files>
# Protect application and system files from being viewed
RewriteRule ^(?:application|modules|system)\b.* index.php/$0 [L]
# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Rewrite all other URLs to index.php/URL
RewriteRule .* index.php/$0 [PT]
#-SetEnv KOHANA_ENV "production"
and in the bootstrap i have set the site_url to '/'
I had same problem when I moved kohana from localhost to linux hosting.
Try to rename your controller files in capital letters. In bootstrap routes keep small letters.
It helped me.
Please try and post much of the bootstrap.php file as possible. Chances are that you do not have a default root set.
Search within your file for a code block that looks like
Route::set('default', '(<controller>(/<action>(/<id>)))')
->defaults(array(
'controller' => 'default',
'action' => 'index',
));
The keyword being Route::set('default', '(<controller>(/<action>(/<id>)))')
Where is your application hosted? Is it on www or within a subfolder in www?
What you're seeing is the error that is thrown when you haven't set up your environment to run for the first time to use clean urls. Do this:
go into your .htaccess file and set the correct path for RewriteBase
if your localhost path where localhost/my/site, your htaccess should be:
RewriteBase /localhost/my/site/
(make sure you rename the file so it is ONLY called .htaccess )
Go into your bootstrap.php file and make sure Kohana::init has:
'base_url' => '/localhost/my/site/' in its array.
Inside the /application/classes/Controller/ directory, add your controller file name the file so that the first letter is uppercase (i.e. Welcome.php) and inside the controller, make sure your controller contents are written correctly.
/application/classes/Controller/Welcome.php
That's a good start towards solving the problem.
This exception was throwed because controller not found. By default, '/' URI means calling method action_index() of Controller_Welcome. See bootstrap.php, Route::set('default', ...).
I think, there can be one of these reasons:
You have default route, and application/classes/Controller/Welcome.php was removed.
While upgrading Kohana version to v3.3, you havent replace application folder with new one. So, you have application/classes/controller/welcome.php instead of application/classes/Controller/Welcome.php.
You have changed default route with non-existing controller. Note that Kohana v3.3 has new file/class naming conventions.

Slim Framework always return 404 Error

These days i'm using Slim Framework as my simplest tool to develop the php web api.
Using these two articles:
Coenraets
CodingThis
I follow some of the steps from there. Downloading the Slim Framework, putting the correct directory & files. Adjusting the initation statements such as;
//1. Require Slim
require('Slim/Slim.php');
//2. Instantiate Slim
$app = new Slim();
//3. Define routes
$app->get('/books', function ($id) {
//Show book with id = $id
});
And then, I modify the rest accordingly.
Such as my checklist that already done:
LoadModule rewrite_module modules/mod_rewrite.so -> enabled
Slim .htaccess:
RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule
^(.*)$ bootstrap.php [QSA,L]
httpd.conf: (Shared Link).
But, after Once I run this statement;
$app->run();
And I run it on my browser.... then, I got 404 Error while testing it on my Localhost. What's the solution for fixing that?
FYI, here is my simplest PHP file that i'm currently using it. (shared Link)
Problem is solved!
My apache is actually normal, and the .htaccess file provided earlier also normal.
The clue is the URL that I used.
Previously I used the invalid URL, thus it returned the 404 page error.
I just realized it when I Tried to access the newer GET URL via browser with this one;
http://localhost/dev/index.php/getUsers/user1
and now that works!
I just realized it once I found these statements;
If Slim does not find routes with URIs that match the HTTP request
URI, Slim will automatically return a 404 Not Found response.
If Slim finds routes with URIs that match the HTTP request URI but not
the HTTP request method, Slim will automatically return a 405 Method
Not Allowed response with an Allow: header whose value lists HTTP
methods that are acceptable for the requested resource.
I found this post while googling "slimframework 404". The post led me to a solution to my problem.
The Problem
I set up a site with the Slim framework using Composer and create an index.php with the following example code form slimframework.com:
<?php
$app = new \Slim\Slim();
$app->get('/hello/:name', function ($name) {
echo "Hello, $name";
});
$app->run();
Then I try to access the page using http://localhost/hello/bob. I get back a 404 Page Not Found page.
I was able to get to access the page using http://localhost/index.php/hello/bob.
The Solution
I found the solution by looking at /vendor/slim/.htaccess (included w/ Composer Slim install) and the URL Rewriting section of the Slim framework documentation.
I added a copy of the /vendor/slim/.htaccess file to the same folder as my index.php file. The contents of the file are:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
Now I can access the page using http://localhost/hello/bob.
You're right about to include the index.php on your file, but that happen because you're not working properly with your mod-rewrite
Please check the following link:
https://github.com/codeguy/Slim
In the Get Started part you could see how to configure your server (in case that you were using apache / lighttpd / ngynx)
I think your problem is at the "Resource parser" because you are no defining $id parameter at the request so, please, try this:
//1. Require Slim
require('Slim/Slim.php');
//2. Instantiate Slim
$app = new Slim();
//3. Define routes
$app->get('/books/:id/', function ($id) {
echo json_encode( getBook($id) );
});
// some stuff
$app->run();
Please, tell us if it's ok
For me the problem was that I'd forgotten to provide a .htaccess file in my document root.
.htaccess
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [L]
If you're using Slim on Ubuntu 16.04 and you're getting the 404 error. Try this test from Tod Birdsall above:
If this works
http://localhost/index.php/hello/bob
and this doesnt work
http://localhost/hello/bob
and your .htaccess file in the same directory as your index.php and is configured as follows:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
</IfModule>
And you still get the 404 error on Apache.
Try turning on Apache mod_rewrite as follows and restart Apache:
$sudo a2enmod rewrite
$sudo service apache2 restart
The Slim API should work correctly now as the provided .htaccess file will only work if mod_rewrite is enabled and that not the default on a clean install.
Here is how to turn off mod_rewirte if you need to.
$sudo a2dismod rewrite
$sudo service apache2 restart
Additionally mod_rewrite.so module must be loaded in httpd.conf or you will receive error 500.
LoadModule rewrite_module modules/mod_rewrite.so
For people who still search answers because previous doesn't work, this works for me :
RewriteBase /<base_of_your_project>/

CodeIgniter 404 Page Not Found, but why?

I am using CodeIgniter for two applications (a public and an admin app).
The important elements of the document structure are:
/admin
/admin/.htaccess
/admin/index.html
/application
/application/admin
/application/public
/system
.htaccess
index.php
The /admin/.htaccess file looks like this:
DirectoryIndex index.php
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]
The /admin/index.php has the following changes:
$system_folder = "../system";
$application_folder = "../application/admin"; (this line exists of course twice)
And the /application/admin/config/routes.php contains the following:
$route['default_controller'] = "welcome";
$route['admin'] = 'welcome';
Welcome is my default controller.
When I call up the Domain/admin I get a 404 Page Not Found error. When I call up the Domain/admin/welcome everything works fine. In the debug logs I get the following error message:
DEBUG - 2010-09-20 16:27:34 --> Config Class Initialized
DEBUG - 2010-09-20 16:27:34 --> Hooks Class Initialized
DEBUG - 2010-09-20 16:27:34 --> URI Class Initialized
ERROR - 2010-09-20 16:27:34 --> 404 Page Not Found --> admin
Weirdly enough this setup works perfectly on my local MAMP installation (with the localdomain/admin/), but when I publish and test it on the "live" server, I just get 404 errors.
Any ideas? What am I doing wrong?
Thanks
C.
The cause of the problem was that the server was running PHP using FastCGI.
After changing the config.php to
$config['uri_protocol'] = "REQUEST_URI";
everything worked.
You could try one of two things or a combination of both.
Be sure that your controller's name starts with a capital letter. eg "Mycontroller.php"
If you have not made any changes to your route, for some strange reason, you might have to include capital letters in your url. e.g if your controller is 'Mycontroller.php' with a function named 'testfunc' inside it, then your url will look like this: "http://www.yourdomain/index.php/Mycontroller/testfunc". Note the capital letter. (I'm assuming you haven't added the htaccess file to remove the 'index.php' part. If you have, just remove it from the url.)
I hope this helps someone
Leaving this answer here for others who ran into my situation.
My codeigniter app was working fine in localhost/WAMP, but was unable to route and produced 404 not found errors when pushing to an AWS EC2 instance. My issue was solved from the answer from HERE htaccess works in localhost but doesn't work in EC2 instance
(route to my admin page)
{domain}/admin was producing 404
the /etc/httpd/conf/httpd.conf file needs to be modified.
-after every instance of "DocumentRoot "/var/www/html"" (2 places) "AllowOverride None" needed to be changed to "AllowOverride All".
Restarted the EC2 instance from the AWS dashboard.
{domain}/admin is now accessible and working as intended.
hope this helps someone else like it helped me!
Change your controller name first letter to uppercase.
Change your url same as your controller name.
e.g:
Your controller name is YourController
Your url must be:
http://example.com/index.php/YourController/method
Not be:
http://example.com/index.php/yourcontroller/method
we have to give the controller name in lower cases in server side
$this->class = strtolower(__CLASS__);
If you installed new Codeigniter, please check if you added .htaccess file on root directory.
If you didn't add it yet, please add it.
You can put default content it the .htaccess file like below.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#When your application folder isn't in the system folder
#This snippet prevents user access to the application folder
#Submitted by: Fabdrol
#Rename 'application' to your applications folder name.
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
# Submitted by: ElliotHaughin
ErrorDocument 404 /index.php
</IfModule>
Modify apache config file as mentioned below :
sudo nano /etc/apache2/apache2.conf
Goto line no 172 and change
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
to
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
and then finally
sudo systemctl restart apache2
Your folder/file structure seems a little odd to me. I can't quite figure out how you've got this laid out.
Hello I am using CodeIgniter for two applications (a public and an admin app).
This sounds to me like you've got two separate CI installations. If this is the case, I'd recommend against it. Why not just handle all admin stuff in an admin controller? If you do want two separate CI installations, make sure they are definitely distinct entities and that the two aren't conflicting with one another. This line:
$system_folder = "../system";
$application_folder = "../application/admin"; (this line exists of course twice)
And the place you said this exists (/admin/index.php...or did you mean /admin/application/config?) has me scratching my head. You have admin/application/admin and a system folder at the top level?
In my case I was using it on localhost and forgot to change RewriteBase in .htaccess.
I had the same issue after migrating to a new environment and it was simply that the server didn't run mod_rewrite
a quick sudo a2enmod rewrite
then sudo systemctl restart apache2
and problem solved...
Thanks #fanis who pointed that out in his comment on the question.
If your application is in sub-folder then the Folder name in directory and URL must be same (case-sensitive).
It happens cause of multiple reasons but the answer missing above there's the "className" while extending your controller.
Make sure your class name is the same as your controller name is your controllers. e.g.,
If your controller name is Settings.php, you must extend the controller like.
class Settings extends CI_Controller
{
// some actions like...
public function __construct(){
// and so and so...
}
}

Categories