Laravel 5 - Routes error: NotFoundHttpException - laravel-5

Similar to the unsolved
WAMP, Laravel 5: Routes not working - NotFoundHttpException
I am trying to pick up Laravel but the routes do not work at all (save for '/').
Using WAMP on Windows 7, I have done the following already in an attempt to rectify the situation;
Enabled rewrite_module
My .htaccess:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
My routes.php:
<?php
Route::get('contact', 'PagesController#contact');
Route::get('/', function () {
return view('welcome');
});
Route::group(['middleware' => ['web']], function () {
//
});
My PagesController.php:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
class PagesController extends Controller
{
//
public function contact()
{
return 'Test Contact';
}
}
When I go to the aliased http://localhost/laravel.dev/ it shows the landing page, but when I navigate to http://localhost/laravel.dev/contact it returns:
NotFoundHttpException in RouteCollection.php line 161:
in RouteCollection.php line 161
at RouteCollection->match(object(Request)) in Router.php line 802
at Router->findRoute(object(Request)) in Router.php line 670
at Router->dispatchToRoute(object(Request)) in Router.php line 654
at Router->dispatch(object(Request)) in Kernel.php line 246
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 52
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in CheckForMaintenanceMode.php line 44
at CheckForMaintenanceMode->handle(object(Request), object(Closure))
at call_user_func_array(array(object(CheckForMaintenanceMode), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
at Pipeline->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
at Pipeline->then(object(Closure)) in Kernel.php line 132
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 99
at Kernel->handle(object(Request)) in index.php line 54
Any help will be greatly appreciated as I have been reading up on and attempting solutions for days now.

Could you try this .htaccess:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteBase /laravel.dev/
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>

Related

axios post request return status 301 on the server

i have problem with vuejs post method on server
my axios request in local is post method and its work fine but when i uploading project in server it dosent work and server return status 301
how can i solve it?
this is my vuejs code
getLogin() {
axios
.post(this.$baseUrl + "login", {
email : this.email,
password : this.password
})
.then(res => {
if(res.data.status == "loggedIn")
window.location.reload()
else
this.data = res.data
})
},
my login function
public function login(Request $req) {
$data = $req->only("email", "password");
if (Auth::attempt($data)) {
$resp = ["status" => "loggedIn"];
return $resp;
}else{
$resp = ["status" => "loginError"];
return $resp;
}
}
the htaccess file
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Send Requests To Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>

Laravel unable to retrieve the correct current page no. which result pagination is not working(showing the first page result only)

Let us consider an example
https://www.example.net/xyz?page=2
Route::get('/xyz', 'controller#getpages');
public function getpages() {
$variable=Model::paginate(10);
dd($variable);
}
i have done "dd($variable);" in function . which gives the result of
LengthAwarePaginator {#1209 ▼
#total: 4341
#lastPage: 435
#items: Collection {#1211 ▶}
#perPage: 10
#currentPage: 1
#path: "www.example.net/xyz"
#query: []
#fragment: null
#pageName: "page"
}
dd($request);
Request {#38 ▼
#json: null
#convertedFiles: null
#userResolver: Closure {#1028 ▶}
#routeResolver: Closure {#1029 ▶}
+attributes: ParameterBag {#40 ▶}
+request: ParameterBag {#46 ▶}
+query: ParameterBag {#46 ▶}
+server: ServerBag {#42 ▶}
+files: FileBag {#43 ▶}
+cookies: ParameterBag {#41 ▶}
+headers: HeaderBag {#44 ▶}
#content: null
#languages: null
#charsets: null
#encodings: null
#acceptableContentTypes: null
#pathInfo: "/xyz"
#requestUri: "/xyz?page=2"
#baseUrl: ""
#basePath: null
#method: "GET"
#format: null
#session: Store {#112 ▶}
#locale: null
#defaultLocale: "en"
-isForwardedValid: true
}
dd($request->all());
it is showing
array:1 [▼
"/xyz" => null
]
in the site which have error. but rest of the sites whose pagination working properly . gives the below output.
array:1 [▼
"page" => "2"
]
instead of #currentPage: 2 . it was working properly, But from yesterday it is happening like this through all our site. so how can I fix this?
Note: I have used this same code in multipage sites. but it is not working in it only
i got the proper issue here.In our whole site the passing to controller . and in validation . it is not mention how can i resolve this.
Defected htaccess file
RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
#RewriteEngine On
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]
#RewriteCond %{THE_REQUEST} ^.*/index\.php
#RewriteRule ^(.*)index.php$ /$1 [R=301,L]
##Redirect 301 /index.php https://www.example.net/
#RewriteEngine On
#RewriteCond %{HTTP:X-Forwarded-Proto} !https [OR]
#RewriteCond %{HTTP_HOST} !^www. [NC]
#RewriteRule ^(.*)$ https://www.example.net/$1 [L,R=301]
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteBase /
RewriteRule ^api/(.*)?$ http://127.0.0.1:8888/$1 [P,L]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
corrected htaccess file
RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]
#RewriteEngine On
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteRule ^(.*)$ /index.php?/$1 [L]
#RewriteCond %{THE_REQUEST} ^.*/index\.php
#RewriteRule ^(.*)index.php$ /$1 [R=301,L]
##Redirect 301 /index.php https://www.example.net/
#RewriteEngine On
#RewriteCond %{HTTP:X-Forwarded-Proto} !https [OR]
#RewriteCond %{HTTP_HOST} !^www. [NC]
#RewriteRule ^(.*)$ https://www.example.net/$1 [L,R=301]
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteBase /
RewriteRule ^api/(.*)?$ http://127.0.0.1:8888/$1 [P,L]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
I have tried your code, working fine for me. couldn't able to find out the problem with your code based on the information given. if it is not working, please set the currentPage manullay in you controller. so you controller would be like
public function getpages(Request $request) {
Paginator::currentPageResolver(function() use ($request){
return $request->page;
});
$variable=Model::paginate(10);
dd($variable);
}

Codeigniter controller action routing issue

I am beginner in Codeigniter.
In .htaccess file
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
In config.php file I have made changes as
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
$config['url_suffix'] = '';
$config['base_url'] = '';
In route.php file I have made changes as
$route['products/register'] = 'products/register';
$route['products'] = 'products';
$route['default_controller'] = 'products';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
Products Controller
<?php
if (!defined('BASEPATH'))
exit('No direct script access allowed');
class Products extends CI_Controller {
public function __construct(){
parent::__construct();
$this->load->helper(array('form', 'url'));
$this->load->library(array('session', 'form_validation', 'email'));
$this->load->database();
$this->load->model("product_model");
}
public function index()
{
die("aaaaa"); exit;
}
public function register()
{
die("DSds");
}
}
When I request url in browser http://localhost/codei/products/register its shows 404 Page Not Found
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
Try the above code in .htaccess and also set base url in config file
$config['base_url'] = 'http://localhost/codei/';
Use this it will definitely work for you.
Don't do anyting else all are perfect.
Only replace .htaccess code
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
note: Make sure rewrite_mode is on in apache

404 page not found in codeigniter 3

I am having 404 when I uploaded the codeigniter to server. I tried every known method and still unable to find the solution
My .htaccess
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^system.*
RewriteCond $1 !^(index\.php|images|js|uploads|css|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
config.php
$config['base_url'] = 'http://example.com';
$config['index_page'] = '';
$config['uri_protocol'] = 'QUERY_STRING';
routes.php
$route['default_controller'] = 'lloyd';
Controller lloyd.php
if (!defined('BASEPATH'))
exit('No direct script access allowed');
class Lloyd extends CI_Controller{
public function __construct() {
parent::__construct();
}
public function index()
{
$theme = $this->aauth->get_system_var("theme");
$this->load->view($theme . '/home');
}
}
First with your uri_protocol
Try This
$config['uri_protocol'] = 'REQUEST_URI';
Instead of
$config['uri_protocol'] = 'QUERY_STRING';
File names must have first letter upper case on CI3 versions same with classes.
Lloyd.php
Instead of
lloyd.php
With base url all ways good to use / at end also.
$config['base_url'] = 'http://example.com/';
Make sure you have the htaccess file on the main directory of your project.

Codeigniter first attempt

I'm new to MVC and Codeigniter, but I have something working although not as I'd like and wondered if someone could help me?
I have 2 pages in my website (league, players) in a codeigniter sub-directory and currently my URL to get to them are 'http://www.mydomain.co.uk/codeigniter/index.php/golf' and 'http://www.mydomain.co.uk/codeigniter/index.php/players'
1) How to I remove the index.php from the URL? I've tried $config['index_page'] = ''; in config/config.php and set the .htaccess file, but no luck.
2) I only want to point my default controller in routes.php to golf controller and let the controller handle whatever page is being asked for.
3) Have I set this up correctly or if not then what is the proper way? One controller OK?
.htaccess
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ codeigniter/index.php/$1 [L]
config/routes.php
$route['default_controller'] = 'golf';
$route['players'] = 'golf/players'; <-Don't really want this entry!
config/autoload.php
$autoload['libraries'] = array('database');
$autoload['helper'] = array('url');
controllers/golf.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Golf extends CI_Controller {
public function __construct() {
parent::__construct();
}
public function index() {
$this->load->model('league_model');
$data['league'] = $this->league_model->get_League();
$data['title'] = 'League Table';
$this->load->view('templates/header', $data);
$this->load->view('templates/menu');
$this->load->view('league', $data);
$this->load->view('templates/footer');
}
public function players() { //Runs because of entry in config/routes.php
$route['players'] = 'golf/players';
$data['title'] = 'Players';
$this->load->view('templates/header', $data);
$this->load->view('templates/menu');
$this->load->view('players', $data);
$this->load->view('templates/footer');
}
}
?>
models/league_model.php
<?php
class League_model extends CI_Model {
public function __construct() {
}
public function get_League() {
$this->db->from("player");
$this->db->order_by("name", "asc");
$query = $this->db->get();
return $query->result_array();
}
}
?>
views/league.php
<p><?php echo $title; ?></p>
<?php foreach ($league as $item): ?>
<p><?php echo $item['name']." : ".$item['handicap']." : ".$item['bbnetbirdie']." : ".$item['bb4p'] ?></p>
<?php endforeach ?>
views/players.php
<p>This is players</p>
You .htaccess should look like this
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase codeigniter/
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
And in config $config['index_page'] = ''; this is perfect
A simple .htaccess file i use :
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
and on the config.php file, removing any reference to index.php
$config['index_page'] = ''

Resources