Routing for subpages on production server not works - php

I am working on Lunux. My created locally webpage works good but after I sent on production server only mainpage is routing, subpages not.
For example address https://demo.tiltkomp.pl/ is working but https://demo.tiltkomp.pl/about return "NetworkError: 404 Not Found - https://demo.tiltkomp.pl/about"
my web.php:
Route::get('/', 'PagesController#index');
Route::get('about', 'PagesController#about');
in PagesController.php:
class PagesController extends Controller
{
public function index(){
return view('pages.index');
}
public function about(){
return view('pages.about');
}
}
Where do I make mistake ?

Please check this answer https://stackoverflow.com/a/28031497/5130217
So in case you using Apache you need to check mod_rewrite enabled and Override allowed in apache2.conf file.

Related

The get in laravel doesn't find any page

I am very a beginner in Laravel
I launch my laravel project on localhost
<http://localhost/ecommerce/public/>
Route::get('/', function () {
return view('welcome');
});
this give me the welcome page
But I want to add about page but it always say "404 Not found"
and that's my code:
Route::get('/about', function () {
return view('about');
});
I made a file in views and called it "about.blade.php"
when I type to view about like this :
Route::get('/', function () {
return view('about');
});
and remove the welcome get, it works and give the about page
but when I put it in get "/about" it always doesn't work, even if I just type "string"
why it can't recognize get "/about"?
You should run the project with php artisan serve in terminal or in the server you have to change document root and remove the public in URL
the reason is the extra public in your url

Showing wrong view in laravel 5.4

I am using laravel 5.4 and trying to get index page, i am using following routes
Route::get('/',
['as' => 'home_page',
'uses' => 'Controller#index']);
and index function in controller looks like this:
public function index()
{
return view('index');
}
But when I visit mydomain.com, I get a different view than index.blade.php.
and it is fine when I use mydomain.com/? or on my local server.
I have searched everywhere in my code and in a google, but didn't found anything, any help?
ie: let me know if any further information required.
First make sure you are calling the right controller, and this dont have a specific middleware blocking the acess to your index method and index.blade.php is inside view folder.
If all of this is fine try this code on your rotes file:
Route::get('', function () {
return view('index');
})
Try this.
First use the make:controller Artisan command to create a controller file. let's say it is homeController.
php artisan make:controller homeController
Then in the homeController file write your code to get the view.
<?php
namespace App\Http\Controllers;
class homeController extends Controller
{
public function index()
{
return view('index');
}
}
Then define a route to this controller.
Route::get('/', 'homeController#index');
For more information please refer https://laravel.com/docs/5.5/controllers
There was a cached view saved on my server, I used
php artisan cache:clear and it got fixed. Thank you everyone for the support.

Routing with index file laravel 5.4

I'm trying to setup my laravel project but I cant seem to get routing to work. This is my routes/web.php:
Route::post('test','UserController#test');
Route::resource('/','UserController');
Now my / works. The functions in it work, but Laravel says my test does not exist. I get a 404 error.
In my / index I have a form like this:
<form method="POST" action="test">
It goes from laravel/public/ to laravel/public/test. But apparently laravel/public/test gives back a 404 error. I tried to fix it with: Route::post('/test','UserController'); but it gives the same error. The only 2 differencex with the documentation that I see is that I'm working from / which shouldnt make a difference(?) and that I'm not working directly from localhost/ but with some maps where I stored my project. Which shouldnt make a difference either. What am I doing wrong here?
EDIT:
My controller:
class UserController extends Controller{
public function index()
{
return view('testindex');
}
public function test(){
return 'test';
}
}
You should then fix it by one of the following:
public function postTest(){
return 'test';
}
or in routes/web.php
Route::post('test','UserController#test');
You're using wrong web server settings. You need to point web server to the public directory inside Laravel root and use correct settings.
For Apache:
DocumentRoot "/path_to_laravel_project/public"
<Directory "/path_to_laravel_project/public">
For nginx:
root /path_to_laravel_project/public;

NotFoundHttpException Laravel 4

I have a problem with my app on the server.
When I access it through various links, it works. But, when I put the URL to the same site in my browser, I get a NotFoundHttpException. What I have detected in the message of the exception are the following problems:
REDIRECT_URL /app/public//login
REQUEST_URI /app/public//login
I do not understand why it adds two slashes (//) after public instead of one (/).
The code for my file route.php is:
Route::get('login', 'UserController#get_index');
And, the code for my Controller is:
public function get_index()
{
return View::make('admin.login');
}
I think changing the naming convention to the one laravel uses will fix this problem.
Do this in your routes:
Route::get('login', 'UserController#getIndex');
and this in the controller:
public function getIndex()
{
return View::make('admin.login');
}

How to: make my routes start working with Laravel 4?

I am new in Laravel (v4.0.5) and according the website http://laravel.com/docs/routing and other book I found, make a route its as easy as this
Route::any('foo', function()
{
return 'Hello World';
});
so, I try at my host
http//myhost/public/foo
(and I have to use /public due if i only enter to my host directly where is the folder, I see the structure of the framework... anybody know why is that?)
But I get not found
I've tried
Route::any('user','UserController#index');
I have created my controller like this
<?php
class UsersController extends BaseController {
public function showWelcome()
{
return View::make('users');
}
public function getIndex()
{
return View::make('users');
}
}
And tried with /users but nothing...
Any idea what I'm doing wrong?
Try going here:
http://myhost/public/index.php/foo
You will need to setup URL rewrites if you want it to work with
http://myhost/public/foo
http://httpd.apache.org/docs/current/mod/mod_rewrite.html
You should point the web root of your server to the public folder. If you're using Apache, you can change this on the httpd.conf file, looking for DocumentRoot setting. Example:
DocumentRoot "C:\Users\Raphael\Documents\GitHub\RaphStore\public"
This is important because it makes sure no one has access to your project files, as it should be.

Categories