So I got exactly this 404 error :
Not Found
The requested URL /adminigniter1/Usercontroller/insert was not found on this server.
Apache/2.4.18 (Ubuntu) Server at localhost Port 80
When I wanted to call a function from the controller, from what I read about it has to do with the .htaccess file(and I placed that in my source folder adminigniter1), but mine seems to look ok:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /adminigniter1/index.php
</IfModule>
From my index.php I send to that controller function like this:
<form method = "POST" action = "<?php echo base_url('Usercontroller/insert') ?>">
And this is my controller :
<?php
class Usercontroller extends CI_Controller {
function __construct() {
parent::__construct();
$this->load->model('Usermodel');
}
public function index() {
$data["content"]= "user/index";
$data["getStatus"] = $this->Usermodel->getStatus();
$this->load->view("main",$data);
}
public function insert() {
$datai= $this->input->post();
if(isset($datai)){
echo $datai['txtApartament'];
exit;
}
}
}
What can be wrong ?
Ok, I found the reason for that, I will post it here since some one can have this problem. All the issues were on apache2 side:
If you use ubuntu go :
sudo gedit /etc/apache2/apache2.conf
There you will have to edit field like this :
<Directory /var/www/html/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
In my case AllowOverride was set to None, so you will have to set it to All, another thing, check the root for your localhost /var/www/html/ in my case, to be ok!
Related
Solution
The solution was found thanks to #Gert B.
Simply add to your Laravel application any virtual host (I added for mine)
laravel1.test
How to add Virtual host:
Go to C:\Windows\System32\drivers\etc\hosts
add line:
127.0.0.1 laravel1.test (or your virtual host name)
And add this to your vhosts(in case of using xampp) in C:\xampp\apache\conf\extra httpd-vhosts
<VirtualHost *:80>
ServerName www.laravel1.test
ServerAlias laravel1.test
DocumentRoot "C:\xampp\htdocs\Laravel1\public"
<Directory "C:\xampp\htdocs\Laravel1\public">
# use mod_rewrite for pretty URL support
RewriteEngine on
# If a directory or a file exists, use the request directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Otherwise forward the request to index.php
RewriteRule . index.php
# use index.php as index file
DirectoryIndex index.php
# ...other settings...
# Apache 2.4
Require all granted
## Apache 2.2
# Order allow,deny
# Allow from all
</Directory>
</VirtualHost>
I can't pass the problem with routing in Laravel 8.5 framework. I know there have been many requests about this problem so far but any of given solutions didnt help in my case. I will show Frontend code, since backend is the same thing and also doesnt work. Right now, the only thing that works is index.php.
I know thanks to newest Laravel all bugs are hidden under simple error 404.
Bug image
I already tried:
Changing in apache/conf/httpd solution AllowOverride All
Clearing whole cache and routes cache
Any possible misspells in code
Still, without any working anwser.
My FrontendController at app/Http/Controllers
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class FrontendController extends Controller
{
public function index()
{
return view('frontend.index');
}
public function object()
{
return view('frontend.object');
}
public function article()
{
return view('frontend.article');
}
public function person()
{
return view('frontend.person');
}
public function room()
{
return view('frontend.room');
}
public function roomSearch()
{
return view('frontend.roomsearch');
}
}
My web.php at app/routes
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\FrontendController;
##Frontend routes
Route::get('/','FrontendController#index')->name('index');
Route::get('/object','FrontendController#object')->name('object');
Route::get('/article','FrontendController#article')->name('article');
Route::get('/person','FrontendController#person')->name('person');
Route::get('/room','FrontendController#room')->name('room');
Route::get('/roomSearch','FrontendController#roomsearch')->name('roomSearch');
##Backend routes
Route::group(['prefix'=>'admin'],function(){
Route::get('/','BackendController#index')->name('adminHome');
Route::get('/cities','BackendController#cities')->name('cities');
Route::get('/myObjects','BackendController#myobjects')->name('myObjects');
Route::get('/profile','BackendController#profile')->name('profile');
Route::get('/saveObject','BackendController#saveobject')->name('saveObject');
Route::get('/saveRoom','BackendController#saveroom')->name('saveRoom');
});
.htacces file in app/public
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
Options +FollowSymlinks
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
My routes
image
Solution
The solution was found thanks to #Gert B.
Simply add to your Laravel application any virtual host (I added for mine) laravel1.test
How to add Virtual host: Go to C:\Windows\System32\drivers\etc\hosts
add line:
127.0.0.1 laravel1.test (or your virtual host name)
And add this to your vhosts(in case of using xampp) in C:\xampp\apache\conf\extra httpd-vhosts
<VirtualHost *:80>
ServerName www.laravel1.test
ServerAlias laravel1.test
DocumentRoot "C:\xampp\htdocs\Laravel1\public"
<Directory "C:\xampp\htdocs\Laravel1\public">
# use mod_rewrite for pretty URL support
RewriteEngine on
# If a directory or a file exists, use the request directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Otherwise forward the request to index.php
RewriteRule . index.php
# use index.php as index file
DirectoryIndex index.php
# ...other settings...
# Apache 2.4
Require all granted
## Apache 2.2
# Order allow,deny
# Allow from all
</Directory>
</VirtualHost>
I'm trying to create a website with Twig and Silex but I get a 404 Not Found error when I want access to /test page.
http://127.0.0.1/public_html/M1-CSI/web/ works.
http://127.0.0.1/public_html/M1-CSI/web/test doesn't works.
.htaccess
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
</IfModule>
Routing file
<?php
$routes = $app['controllers_factory'];
$routes->get('/', 'Sources\\Controllers\\ExempleController::exemple');
$routes->get('/test', 'Sources\\Controllers\\ExempleController::test');
return $routes;
Controller
<?php
namespace Sources\Controllers;
use \Silex\Application;
class ExempleController {
public function exemple(Application $app) {
return $app['twig']->render('exemple.html.twig', array('exempleValue' => 3));
}
public function test(Application $app) {
return $app['twig']->render('test.html.twig');
}
}
Thank's a lot.
EDIT
You can find source code extract here : https://github.com/nlamblin/website-boilerplate
SOLUTION
Problem solved.
I added these code lines :
<Directory /var/www/html/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
in /etc/apache2/sites-available/000-default.conf
I am trying to set up a development environment on Windows with xampp 5.6.23.
I have an API I want to set up with Restler 3.0.0 so that I can browse to http://localhost/api/cars/search?term=red to call the search($term) function in the C:\xampp\htdocs\api\cars.php file:
<?php
class cars{
public function search($term) {
// do search...
return $result;
}
}
I also have a C:\xampp\htdocs\api\index.php set up with:
<?php
require_once 'vendor/autoload.php';
require_once 'vendor/luracast/restler/vendor/restler.php';
use Luracast\Restler\Restler;
Defaults::$crossOriginResourceSharing = true;
$r = new Luracast\Restler\Restler();
$r->setCompatibilityMode('2');
$r->setSupportedFormats('JsonFormat', 'XmlFormat', 'JsFormat');
Luracast\Restler\Format\JsonFormat::$unEscapedUnicode = false;
$r->addAPIClass('cars');
$r->addAPIClass('Luracast\\Restler\\Resources');
$r->handle(); //serve the response
and C:\xampp\htdocs\api\.htdocs:
DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^$ index.php [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
<IfModule mod_php5.c>
php_flag display_errors On
</IfModule>
But if I go to any URL (/ or /cars) I get a 404 error:
<response>
<error>
<code>404</code>
<message>Not Found</message>
</error>
<debug>
<source>Routes.php:431 at route stage</source>
<stages>
<success>get</success>
<failure>route</failure>
<failure>negotiate</failure>
<failure>message</failure>
</stages>
</debug>
</response>
I have tried multiple answers from SO but none have worked in my instance. I have uncommented LoadModule rewrite_module modules/mod_rewrite.so and set AllowOverride All everywhere I could find it in httpd.conf. I have also tried moving my everything to htdocs instead of a sub folder but still get the same result.
Since you don't have an index() function but only a search() function in your class cars, you need to access the URL /cars/search/term.
Or are you trying to achieve something else?
I am using Codeigniter 3. When running on local wamp server, all is good. But, when running on my VPS (Linux Debian Apache 2.2.22) I get a 'URL not found' message.
here is the controller:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Contact extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->helper('url');
$this->load->library('session');
$this->load->helper('form');
}
public function index()
{
$this->load->view('contact_view');
}
}
My URL to this controller is www.example.com/Contact
Error message is:
The requested URL /index.php/Contact was not found on this server.
I have removed index.php from $config['index_page'] = ''
In my .htaccess file, I am using rewrite to eleminite the need for index.php in URLs, using this:
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
The directives on my virtual host are:
<Directory "/var/www/example">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
mod_rewrite is definitely enabled on virtual host.
Everything works fine on my local machine, running Wampserver, but why does it not work on my VPS?
For Codeigniter 3, I had to Capitalize the first letter of the Controller filename. So for example, I changed main.php to be Main.php and that fixed it for me.
Note that I did not have to do that on my localhost windows laptop, but I had to do that on the hostgator unix server.
RewriteRule ^(.*)$ index.php?/$1 [L]
Question mark after index.php is solution... However, i would like some explanation, too. I know from experience that some servers requires it, but don't know the exact reason.
I'm trying to setup Slim for me application i've got issue that route with parameters not working.
This is my index.php
require 'Slim/Slim.php';
\Slim\Slim::registerAutoloader();
$app = new \Slim\Slim();
// GET route
$app->get('/', function () {
print "hello";
});
$app->get('/books/:id', function ($id) {
print $id;
});
$app->run();
This is the .htaccess file
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
Request to / works fine, but if I pass /books/1 it returns [404] not found
Man your mod_rewrite is not enable in apache.For enable mod_rewrite follow this.Reference http://www.kingpabel.com/apache-mod-rewrite/
<Directory /var/www/html>
AllowOverride All
</Directory>
//enable mod rewrite
a2enmod rewrite
//restart apache
service apache2 restart