I am new and install Laravel 6.x. And then I got a welcome(default) page.
But I didn't use the sub-directory in the website URL
I created the sub-directory like this below.
"www.test.com/test"
But that is not working.
/routes/web.php code source
It is working well.
Route::get('/', function () {
return view('./posts/test');
});
It is not working. So I got the "404" page.
Route::get('/test', function () {
return view('./posts/test');
});
How can I use sub-directory?
The problem was the Apache configuration:
<Directory "/home/....../public">
AllowOverride all
</Directory>
(posted as a community wiki-answer because this question has been answered in the comments)
Related
First of all: this is not a duplicate of (How to set up a laravel project on cPanel subdomain?) this question isn't the same as mine.
I would like to know how can i set up a whole Laravel application, with subdomains (not only one subdomain) to work on a cPanel server
So here is the test code i'm using on my routes/web.php file.
Route::domain('test.mydomain.com')->group(function() {
Route::get('/', function() {
return 'DOMAIN TEST.MYDOMAIN.COM';
});
});
Route::domain('mydomain.com')->group(function() {
Route::get('/', function() {
return 'DOMAIN MYDOMAIN.COM';
});
});
Route::get('/', function() {
return 'ROOT DOMAIN';
});
I'm currently using cPanel to handle domains and subdomains, but i have no idea how to make it work with Laravel Subdomains, i tried the code above.
When i access my main domain mydomain.com it shows "DOMAIN MYDOMAIN.COM" so it works ok, but when i go to test.mydomain.com it just access my subdomain folders from this subdomain, so, how can i make it works?
Maybe i need to put some .htaccess file to get this working properly? Can someone help?
Did you try to link subdomains to the same folder as primary domain ?
Eg.
domain.com => /public_html/public
test.domain.com => /public_html/public
I'm developing API in Laravel 8. I want to handle NotFoundHttpException to json response. But App\Exception\Handler updated in Laravel 8. By default render method does not exist. So I do not understand what I want to do. I have read in Laravel docs.
You can use a custom callback as per the documentation, App\Exceptions\Handler:
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
public function register()
{
$this->renderable(function (NotFoundHttpException $e, $request) {
return response()->json(...);
});
}
If you send the correct accept header with your request the exception handler will return a JSON response already though.
Laravel 8.x Docs - Error Handling - Rendering Exceptions
if you are running on Xamp , edit vhosts where lvauth is your project and directory name
DocumentRoot "C:\xampp\htdocs\lvauth\public"
ServerAdmin lvauth
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
if you are running on Xamp , edit vhosts where lvauth is your project and directory name
VirtualHost lv.auth:80
DocumentRoot "C:\xampp\htdocs\laravel\public"
ServerAdmin lv.auth
<Directory "C:\xampp\htdocs\laravel">enter image description here
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
Directory
VirtualHost
I have pointed some subdomains to my project in laravel, some similar subdomain exists on the same server, but pointed to other projects.
Still sometimes they point to my project.
How to resolve this issue?
route structure-
I have a wildcard route-
Route::group(array('domain' => '{subdomain}.website.com'), function () {
Route::get('/', function ($subdomain) {
});
});
My subdomain which are pointed to this project are-
Xyz.website.com, abc.website.com
but other links like feh.website.com which are pointed to other projects are sometimes pointing to my project.
Please help for above scenario .
I thought it depends on your web server config.
If you use nginx as web server, you should declare the server name:
{
...
servername xyz.website.com abc.website.com
...
}
If you get some else url point to your project like feh.website.com, that maybe because you did not declare settings for feh.website.com and it will go to your first virtual server.
I need to update a website from a colleague to just add a LDAP connexion.
I use EasyPHP devserver 17.0 with php 7.1.3 and MySQL 5.7.17.
I've read a lot of docs etc to be started and to recover the site in local as it is working actually.
Everything was working so I began to add a login form etc... but when I tried to test a link from the website, it return me the error "Sorry, the page you are looking for could not be found". So I began to search on forums I found some results about routes etc and everything I've tested didn't worked.
So, I decide to use the backup from the website as it was when I juste restore it in local(I precise link to other page and everything was working). I check the link and again, "Sorry, the page you are looking for could not be found". I decide to try another developement tool and download XAMP, exactly same error. I tried with Wamp, Laragon always same error.
In the apache conf mod_rewrite is enabled.
My laravel framework version is: 5.5.39
So my folder look like:
Laravel 5.5.39
The content of routes > web.php:
Route::get('/', function () {
return view('welcome');
})->name('welcome');
// Holidays
Route::get('/holidays/create', 'HolidayController#create')->name('holidays.create');
Route::post('/holidays', 'HolidayController#store')->name('holidays.store');
Route::get('/holidays/{holiday}/delete', 'HolidayController#destroy')->name('holidays.destroy');
Route::get('/holidays/{holiday}/edit', 'HolidayController#edit')->name('holidays.edit');
Route::post('/holidays/{holiday}', 'HolidayController#update')->name('holidays.update');
// Leave types
Route::get('/types/create', 'TypeController#create')->name('types.create');
Route::post('/types', 'TypeController#store')->name('types.store');
Route::get('/types/{type}/delete', 'TypeController#destroy')->name('types.destroy');
Route::get('/types/{type}/edit', 'TypeController#edit')->name('types.edit');
Route::post('/types/{type}', 'TypeController#update')->name('types.update');
// Users
Route::resource('users', 'UserController');
Route::get('/births', 'UserController#getAllBirths')->name('births');
// Leaves
Route::get('/calendar', 'LeaveController#index')->name('calendar');
Route::post('/leaves', 'LeaveController#store')->name('leaves.store');
Route::post('/leaves/{leave}', 'LeaveController#update')->name('leaves.update');
Route::get('/leaves/{leave}/delete', 'LeaveController#delete')->name('leaves.delete');
Route::get('/leaves', 'LeaveController#getAll')->name('leaves');
Route::get('/config', 'ConfigController#index')->name('config');
// Stats
Route::get('/statistics', 'StatsController#index')->name('stats.index');
Auth::routes();
I don't know what I could do but please ask me if you need more information to help me.
If it can help; gitLab link from the site I'm trying to restore: https://gitlab.com/balsigergil/btplan
To fix the problem I had to change the VirutalHost DocumentRoot so the root is the public directory.
DocumentRoot "C:/Users/sadm-m263733/Desktop/EasyPHP-Devserver-17/eds-www/siteBTPlan/public"
I am still new to PHP Laravel framework. The problem is that my Laravel routes do not work. Here is the simple code of my routes.php:
<?php
Route::get('/', function()
{
return View::make('hello'); //shows "Hello" page
});
Route::get('somepage', function()
{
return View::make('somepage'); // Apache server shows 404 error
});
I have configured my Apache param AllowOverride All and the mod_rewrite module is loaded. I have another installation of Laravel which works (throws 'NotFound' exception on undeclared route), but this one does not respond properly, on the same server. Where is the problem?
Make sure that your .htaccess file is setup correctly.
http://laravel.com/docs/installation#configuration
Please configure your Apache param AllowOverride All and ensure the mod_rewrite module is loaded.
http://laravel.com/docs/4.2/installation#pretty-urls