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.
Related
I have a very legacy php application, that I'm trying to update to Symfony.
The application currently has a structure similar to this:
/www <-current web root
php_page1.php
php_page2.php
php_pagen.php
/dashboard
dashboard_page1.php
dashboard_page2.php
dashboard_pagen.php
The pages have helper files full of functions and the like, and there's also a few folders full of assets, but that's not really important. So to access a given page you'd point your browser to domain.com/php_page1.php or domain.com/dashboard/dashboard_page1.php... there's no front controller. All pages are accessed directly.
All in all, there's too much to refactor at once, so I want to do it in peices, one page at a time.
What I want to do is install symfony on top of what I have now, so the symfony structure will co-exist with what's currently here:
/www <-legacy
php_page1.php <-legacy
php_page2.php <-legacy
php_pagen.php <-legacy
/app <-symfony
/dashboard <-legacy
dashboard_page1.php <-legacy
dashboard_page2.php <-legacy
dashboard_pagen.php <-legacy
/src <-symfony
/web <-symfony (new web root)
.htaccess <-symfony (points to app.php)
app.php <-symfony (front controller)
I've successfully installed Symfony and migrated a sample legacy page over (Please note the web root moved). This works great.
The trouble is, ultimately, I need Apache to serve the legacy pages if they exist, and go through front controller (app.php) if they do not.
Here's what I've tried.
I've tried various .htaccess rules to try and make Apache serve files in /www and /www/dashboard. These fail, with Symfony telling me there's no route to match to.
I've also tried Symfony's $this->redirect('..\www\php_page1.php');. This fails with Symfony telling me "Looks like you tried to load a template outside of configured directories."
Finally I tried to add /dashboard as a route:
/**
* #Route("/cvdashboard/{file}")
*/
public function cvdashboardAction($file) {
return $this->render("#dashboard/$file");
}
And added a twig path:
twig:
...
paths:
'%%kernel.root_dir%/../dashboard':dashboard
This yealds three exceptions:
FileLoaderLoadException in FileLoader.php line 118:
InvalidArgumentException in YamlFileLoader.php line 371:
ParseException in Inline.php line 108:
Question
So my question is:
How can I configure Symfony / Apache such that if a url that currently exists is called (i.e. domain.com/php_page1.php) it will serve that page either through Symfony or Apache directly and if it does not exist, have Symfony's front controller handle the request?
EDIT
Here's the .htaccess I currently have:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . app_dev.php [L]
This works for Symfony and routes anything I have a defined route for. The problem is that it's in /www/web (new web root), which is where Symfony wants the web root to be. It won't access anything in /www or /www/dashboard, which is outside the web root.
I'm trying to use .htaccess to either cause Apache to grab files from one level down from the web root, or cause Symfony to serve those pages as the generic php scripts they are.
You can use mod_rewrite for that:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d # not an existing dir
RewriteCond %{REQUEST_FILENAME} !-f # not an existing file
# redirect to the symfony app.php file
RewriteRule ^(.*)$ www/app.php [L]
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/
I have a cakephp website and I have located sitemap.php in webroot folder.
I want to rewrite its url in .htaccess file to sitemap.xml
but normal php techniques are not working.
I tried using the following.
RewriteRule ^sitemap\.xml$ xmlsitemap.php [L]
RewriteRule ^sitemap$ sitemap.php [L]
but it doesnot work in cakephp.
Any idea how to do this? Any suggestion will be greatly appreciated.
The only file that should be loaded in the webroot directory should be the index.php. Your application should handle the routing from that point. To customize your routes look at the routes.php files in the Config folder.
Have a look at the routing docs.
http://book.cakephp.org/2.0/en/development/routing.html
For cake you want to use the default automagic routes as much as possible.
For example:
/my_widgets/create would map to the MyWdigetsController and the action create()
I would suggest moving whatever functionality you have in your sitemap.php and move it into an existing controller action. You can also use the parseExtensions feature of cake to give you the proper header and load the correct file for you.
Example for getting /sitemap.xml to load your xml sitemap.
In your routes.php
Router::connect(
'/sitemap.xml',
array('controller' => 'pages', 'action' => 'sitemap', 'ext'=>'xml')
);
Router::parseExtensions('xml');
In your PagesController create an action called sitemap. Put whatever code generates your sitemap data in that action.
In your Views/Pages directory create a folder called xml and place a file called sitemap.ctp
In that file place your output for the xml.
I have had problems before if debug is set above 0 so if you do not see any output, try setting debug level to 0
RewriteCond %{REQUEST_URI} ^/sitemap.xml
RewriteRule ^sitemap\.php$ - [L]
I want to change the name of the root directory of a CakePHP install. For example the root is called 'CakePHP_Website' and I want to change it to 'My_Website'.
However when I rename the directory I get the following error:
Missing Controller
Error: MyWebsiteController could not be found.
Error: Create the class MyWebsiteController below in file: app\Controller\MyWebsiteController.php
What is the process for achieving this?
in /app/webroot/index.php to /app/My_Website/index.php add these lines:
define('WWW_ROOT', '/full/path/to/My_Website/');
define('WEBROOT_DIR', 'My_Website');
If My_Website is your app folder and otherwise you have a default installation then you can change the .htaccess in your installation to
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ My_Website/webroot/ [L]
RewriteRule (.*) My_Website/webroot/$1 [L]
</IfModule>
However you will never have to rename the webroot folder in your app.
Or do you want to move the core?
Your question was not completely clear to me, sorry.
The solution is frustratingly simple. CakePHP urls are case sensitive. So when change the root directory to 'My_Website' and then type in 'localhost/my_website' this will throw an error. Instead I have to type in 'localhost/My_Website' and this will work just fine.
.
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.