Lumen GET Requests Return 404 Error - php

define('ROUTE_BASE', 'lumen/public');
$app->get(ROUTE_BASE . '/', function () use ($app) {
return $app->welcome();
});
$app->get(ROUTE_BASE . '/test', function () use ($app) {
return 'test data : 123 abc !';
});
When I access 'localhost/lumen/public/' I can see the 'lumen welcome page'.
But if I try to access 'localhost/lumen/public/test', I receive the following error.
Error: its not found(404).

Laravel expects the public directory to be the webroot of your domain. As this is not true in your case, you will need to make some alterations to your .htaccess.
Options +FollowSymLinks
RewriteEngine On
RewriteBase /lumen/public
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
Also worth noting that instead of using a constant, you can use route groups to achieve the same functionality in your routes.php.
$app->group(['prefix' => 'lumen/public'], function ($app) {
$app->get('/', function () {
//welcome
});
$app->get('test', function () {
return 'test data : 123 abc !';
});
});

your lumen project must be put in webroot of your localhost,domain or virtual host not in subfolder of your webroot without edit your .htaccess.
for access your project in browser : http://lumen.laravel.dev not http://lumen.laravel.dev/public/
I hope this help. sorry for my English :)

Related

Slim Framework routing not working

I'm learning Slim Framework and got stuck with its routing.
Working Code. Code snippet #1:
$app = new \Slim\App();
$app->get("/", function () {
echo "Hello SlimFramework";
});
$app->run();
Not Working. Code snippet #2:
$app = new \Slim\App();
$app->get("/hello/{name}", function (Request $request, Response $response) {
$name = $request->getAttribute('name');
$response->getBody()->write("Hello, $name");
return $response;
});
$app->run();
I'm getting "Not Found
The requested URL /hello/name was not found on this server." for Code snippet #2. Any clue what's going on here ?
.htaccess File
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [QSA,L]
Thanks in advance !
I had to start with clean slate in order to solve this issue for me. #ceejayoz's solution about making sure if .htaccess is working correctly, was a great help to test .htaccess configuration.

Slimphp 3 Nested Group Not working

i have a little problem with slimphp router :
$app->group('/api', function () use ($app) {
// Library group
$this->group('/library', function () use ($app) {
// Get book with ID
$this->get('/books/:id', function ($req, $res) {
echo "books";
});
// Update book with ID
$this->put('/books/:id', function ($req, $res) {
});
// Delete book with ID
$this->delete('/books/:id', function ($req, $res) {
});
});
});
Sending A GET to /api/library/books/1 give me a Page not found Error, where is the problem.
EDIT :
.htaccess
RewriteEngine On
# Some hosts may require you to use the `RewriteBase` directive.
# If you need to use the `RewriteBase` directive, it should be the
# absolute physical path to the directory that contains this htaccess file.
#
# RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
PS: a simple app->get is working without any problem,
It is not found as Slim 3 uses {id} as placeholders, not :id as Slim 2 did. Therefore the code would be
$this->get('/books/{id}', function ($request, $response, $args) {
...
});
Found in Slim 3 Documentation for Route Placeholders

htaccess config for slim php framework

I use Slim php framework to build some action inside index.php page:
so this is the way I call my action:
index.php/action1
$app->get('/action1',function () use ($app){
echo "this is action 1";
});
index.php/action2
$app->get('/action2',function () use ($app){
echo "this is action 2";
});
Now I want my url become pretty , such as when type in index/action1
, it will redirect to index.php/action1
Please provide me the solution in creating htaccess to do thatThank and best reagard
Create .htaccess file
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
user group to prefix your route
$app->group('/index', function () use ($app) {
/**
* Route GET /index/action1
*/
$app->get('/action1',function () use ($app){
echo "this is action 1";
});
});

routes not directing in laravel application

I am surprised this is not working but maybe I am missing something...I am trying to access from the main page (index.php) either the login page or the signup page. I created both routes to be handled. When I click on the link, it goes to another page such as /website/login and shows not found. Here is the routes.php code:
Route::get('/', 'MainController#index');
Route::get('login', array('as' => 'login', 'uses' => 'MembersController#loadLoginView'));
Route::get('signup', array('as' => 'signup', 'uses' => 'MembersController#loadRegisterView'));
MembersController code:
<?php
class MembersController extends BaseController {
public function loadRegisterView()
{
return View::make('members.register');
}
public function loadLoginView()
{
return View::make('members.login');
}
}
and inside views I have a folder called members and inside it I got login.blade.php and register.blade.php.
Thanks for the help in advance
To remove the index.php you could use the .htaccess provided on the Laravel website:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
Be sure you're running on an Apache server with Mod_rewrite active. I'm not expert on other servers, so I can't suggest you alternative. On Laravel's website there's this snippet for Nginx:
location / {
try_files $uri $uri/ /index.php?$query_string;
}
Have no idea on IIS server, though.
Otherwise, you'll need to keep the 'index.php' in the url, like http://www.example.com/index.php/login

URI ROUTING in CodeIgnitor_2.1.3 throwing "Not Found" error

I have installed CodeIgniter_2.1.3 and running in
Windows 7
Wamp Server 2.1
PHP 5.3.5
Apache 2.2.17
In \applicationconfig\routes.php, I created
$route['default_controller'] = "welcome";
$route['404_override'] = '';
$route['products/catlog'] = "welcome/getOneMethod";
And in \application\controllers\welcome.php, I created a method
public function index()
{
$this->load->view('welcome_message');
}
public function getOneMethod()
{
echo "hi im in newMethod";
}
http://localhost/CodeIgniter_2.1.3/products/catlog
Now I expect on running this url above on browser to give me the page
hi im in newMethod
But instead i'm getting the error message.
Not Found
The requested URL /CodeIgniter_2.1.3/products/catlog was not found on
this server.
What should i do to make it work correctly?
Doo you visit codeigniter documentation website,You can get help from this url how to create static pages
http://ellislab.com/codeigniter/user-guide/tutorial/static_pages.html
For the given url routes and controller.
you will need to use:
http://localhost/CodeIgniter_2.1.3/index.php/products/catlog/
The index.php part in the url can be removed using htaccess rewrite rule.
In the /codeigniter2.1.3/ folder create an .htaccess file and put the following rule:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /CodeIgniter_2.1.3/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /CodeIgniter_2.1.3/index.php [L]
</IfModule>
Note: This might not be the best way to do it.
EDIT:
Make sure the controller is exactly as bellow,
class Welcome extends CI_Controller {
public function index() {
$this->load->view('welcome_message');
}
public function getOneMethod() {
echo "hi im in newMethod";
}
}
and the routes are as bellow:
$route['default_controller'] = "welcome";
$route['404_override'] = '';
$route['products/catlog'] = "welcome/getOneMethod";
For the time being remove the htacces, and make it work with index.php in url.
ie:
http://localhost/CodeIgniter_2.1.3/index.php/products/catlog/
Note: since you are able to see the welcome message, there is no problem with your installation or server. there is probably some syntax error. so i recommend you copy paste the above code, as i have checked them and they are working.

Categories