Laravel 5.8 showing 404 Not Found errors - laravel-5

I change the index.php file path public to root. After adding a .htaccess file in the root path (laravel 5.7) every page working fine. But in laravel 5.8 when I click another page, it's showing 404 Not Found.
My .htaccess file is below.
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
#Send request via index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d``
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

The content of a Laravel .htaccess file should look like this:
<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]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
Your webroot has to be set to the /public directory. Don't try to search for other solutions that move the index.php and .htaccess file from /public to the root directory of your Laravel application. There is absolutely no reason why you want to move the webroot from /public to /. index.php sits in /public for a reason. If your webhost does not offer the ability to move the web root to another directory switch your hoster.

It might be that you have created your folder as Example and trying to access it via example
ie
localhost/Example/public
yet accessing it like
localhost/example/public

Related

After uploaded in the cPanel my Laravel project it's showing the 403 - Error message. How to solve the issue?

I have uploaded a Laravel project in cPanel. Project file uploaded in sub folder. I have created the .htaccess file [reference by forums and tutorials] but issue not solve. I am the beginner in Laravel, Please help me.
Folder Path : example.com->public_html->lrvproject->.htaccess
<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>
go to the path lrvproject/public and inside public(folder copy all file and paste outside public folder) here step1 completed.
Step2 . example.com->public_html->lrvproject open index.php file here change the vendor and bootstrap file path like(/../lrvproject/vendor/autoload.php and
/../lrvproject/bootstrap/app.php

How to deploy Laravel Project on Google Cloud Virtual Machine?

I'm trying to deploy my Laravel project on Google Cloud VM, it did directing to my index.php file but it supposed to routing to the controller instead of showing the index.php code line.
Here is the result
Then i try to change the .htaccess file like the code below:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
#I'm adding this code
RewriteRule ^(.*)$ public/$1 [L]
# 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>
And here is the result
After that i remove that line and try to change all the 'AllowOverride None' lines to 'AllowOverride All' inside of apache2.conf file, then remove the lines that prevent .htaccess and .htpasswd files from being viewed by Web clients:
<FilesMatch "^\.ht">
Require all denied
</FilesMatch>
But the result is still same like the first result
And then i'm trying to add this line:
<IfModule dir_module>
DirectoryIndex index.html index.php
</IfModule>
inside of apache2.conf file but then again the result is still same like the first result
I already install Composer inside of the project but it still not working.
Thank you.
P.S: Sorry for my bad English.

how to access website from a sub folder inside the root folder?

I am about to deploy a laravel project. I uploaded all the files and the website is working fine but the only problem is when i try to access my website i.e for example if i try to write mywebsitename.com in the url then public directory is shown which is because i have symblinked my laravel's public folder to the public_html folder. I don't have any idea about how to edit the .htaccess file in order to load the website with mywebsitename.com and not mywebsitename.com/public. My htacess files code is
<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]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
my file directory structure is shown in this image
please help me
I am guessing it is an apache server. If yes;
Ensure your domain mywebsitename.com points to the public_html
Add a .htaccess file in your root directory(public_html) and paste this in
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
I found a solution to this question.
1.Copy all the laravel files inside the public_html folder including the .htaccess file and the index.php file which is suppose to be inside the public folder(keep both the files inside the public folder).
2.Then link your storage to the public folder using SSH, for that open your SSH enter id and password and change directory using "cd domains/yourdomainname.com/public_html"
then give the php artisan command i.e "php artisan storage:link"
(note:- after changing the directory you can give all the php artisan commands like migrate and config:cache or clear:cache as you wish.
3.Now after the all the necessary commands are given you can access your fully functional website including the image display function if you type yourdomainname.com/public on the URL but if you type just your domain name then all the laravel files will appear on the browser to avoid this and to to jump inside the public folder directly create one more .htaccess file outside the public folder but inside the
public_html folder the copy the below given code and then if you just your domain name on the URL then your website will be directly displayed
Options +SymLinksIfOwnerMatch
RewriteEngine On
RewriteRule ^ public [L]
You can use it with RewriteBase directive,
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
RewriteBase /public_html/ # or '/' only depends on your vhost config
# 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]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
I'm not familiar with apache server but the problem should be in the default index file.
For long terms considered, I advise you to use nginx or openresty, it's easier to configurate.

.htaccess rule for SSL and public folder redirecting

I want to edit my .htaccess file so all the requests will be encrypted (I have SSL certificate active). I'm trying to run a Laravel app, which has Index file in public folder and I want to let user access my page without the /public/ part in URL.
So far, I managed to do this:
This part let me access the page without the /public/ part.
RewriteCond %{HTTP_HOST} ^domain.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^domain.com$
RewriteCond %{REQUEST_URI} !public/
RewriteRule (.*) /public/$1 [L]
This part redirects all data to HTTPS:
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://domain.club/public_html/1 [R,L]
The question is, how do I merge these two together? They work separately, but not if I put this together in .htaccess file.
.htaccess file is located in public_html which is located in root folder. Laravel folders (incluing public) are located in this folder.
Try this
.htaccess
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
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>

Laravel routes are not working on live server

I just found the problem on server. all is working fine in my localhost, but on live server, ONLY the home page route is working.
My directory is:
laravel-
css
js
local->
app
HTTP->
Controllers->
Homecontroller
admin->
Groupcontroller
config
...
Here is my htacess
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
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]
RewriteCond %{HTTP:Authorization} ^(.+)$
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
And my route file is:-
Route::get('/group/detail', 'Groupcontroller#index');
Route::get('/group/add', 'Groupcontroller#create');
Route::get('/group/edit/{id}', 'Groupcontroller#edit');
http://www.example.com/home
My home controller is working.I think issue is with admin folder???
http://www.example.com/admin/group/detail
This is not working
Error is encountered :-
Class App\Http\Controllers\Admin\Groupcontroller does not exist
Please help me,Working fine at localhost but not on live.
Thanks in advance
Try and change the content of your .htacess to this
<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]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
Might be you forget to paste .htaccess file from /public folder to /public_html folder
so Just COPY And PASTE the .htaccess file from public folder to /public_html folder
then it will work as local
Path of Groupcontroller is Controllers/admin/Groupcontroller. So in your routes you need to access Groupcontroller with appropriate path.
Route::get('/group/detail', 'admin\Groupcontroller#index');
Route::get('/group/add', 'admin\Groupcontroller#create');
Route::get('/group/edit/{id}', 'admin\Groupcontroller#edit');
Also it is recommended to use CamelCase folder names. that is; change admin => Admin.
Check the namespaces compared to directory names. The cases should match.
You can try the bellow code :
After the domain name add "public" keyword between your API routes
for example:-
https://example.com/public/api/someroute
After this, you may have to update your PHP version .

Resources