Lumen routes not working - laravel

Basically any route I try to create throws me
404 Not Found
The requested resource '/some-route' was not found on this server.
But when I leave web.php like this
<?php
$router->get('/', function () use ($router) {
return $router->app->version();
});
I can run the default route but if I add any other route this route stops working too.
I am trying to add this route, Controller should echo something but it does not reach controller.
$app->get('/cors', 'App\Http\Controllers\CorsController#index');
I tried defining the route with path to controller and without still same thing.
.htacess file is default
My .conf file is like this
<VirtualHost *:80>
DocumentRoot "/var/www/html/lumen-projects/test/public"
ServerName localhost
<Directory "/var/www/html/lumen-projects/test/public">
# Ignore the .htaccess file in this directory
AllowOverride None
# Make pretty URLs
<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>
</Directory>

Related

Laravel: How to configure api.php routes for shared hosting?

I have the following .htaccess fille:
<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>
#disable directory browsing
Options -Indexes
#PROTECT ENV FILE
<Files .env>
order allow,deny
Deny from all
</Files>
#PROTECT ENV FILE
<Files .htaccess>
order allow,deny
Deny from all
</Files>
But the problem is I get a 404 status code in my production environment when trying to load "getservicedata" from a vue.js component. I think the problem is in the URL because it works when I type in the correct url, but the problem is the app loads the API from wrong URL.
I followed this guide to setup laravel shared hosting: https://laravelarticle.com/deploy-laravel-on-shared-hosting

how to config Laravel 6 in subfolder domain?

I have a Laravel 6 app which is working fine locally on redhat apache.
my client setting the domain and must using /abc ater the domain
i.e domain.or/abc
i put my root folder into /var/www/abc/
In config/app.php I have
'url' => 'h t t ps :// domain.or/abc',
In pfi/public/.htaccess I have
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteBase /abc
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
I can access domain.or/abc and the page loads (without styles, images, ...). But all the other links to pages, images, css, js, ... are wrong. For example, they link to
domain.or/css/style.css
instead of linking to
domain.or/PFI/css/style.css
i.e., "PFI" is missing from all the links.
If I go to
domain.or/abc/login
i got 403 error, but if domain.or/login, page load without css,js
and if i open css,js file manually by copy the link to the new tab
i.e domain.or/abc/css/style.css the css dont load, it only show the main page instead of css scripts
in order to fix this issue:
ensure that inside .env file APP_URL=https://domain.or/PFI
ensure the same for config/app.php file 'url' => env('APP_URL', 'https://domain.or/PFI'),
edit your public/index.php you have to change the path of these to line to be consistent with the actual path
$app = require_once __DIR__.'/../path_to_public_folder/bootstrap/app.php';
require __DIR__.'/../path_to_public_folder/vendor/autoload.php';
in .htaccess
<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]
# Redirect http to https
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
<IfModule mod_headers.c>
# Prevent click jacking
Header set X-Frame-Options Deny
Header set X-Frame-Options: SAMEORIGIN
</IfModule>
</IfModule>
I got the answer
The changes i did:(my apps folder is laravel)
create folder on /var/www/ same with ur subfolder domain, sudo mkdir PFI
Create softlink: ln -s /var/www/laravel/public /var/www/PFI
Update httpd.conf
<VirtualHost *:80>
ServerName xxxx
DocumentRoot /var/www/PFI
Redirect permanent / https://xxx/PFI
<Directory /var/www/laravel/public>
AllowOverride All
</Directory>
</VirtualHost>
<VirtualHost _default_:443>
ServerName XXX
DocumentRoot /var/www/PFI
</VirtualHost>
update on my layouts with
and all my css,js change to <href ="css/style.css">

Remove Index.php in url Like " laravel-project/public/login "not " laravel-project/public/index.php/login "

I Get Problem With my laravel project
I want to remove index.php in url
like
http://localhost/react/Lara-react/public/admin/home
And i get 404 not found if use this
but if i use
http://localhost/react/Lara-react/public/index.php/admin/home
it's works and
http://localhost:8000/admin/home
^ works to
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]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
I have tried
https://laravel.com/docs/5.8/installation#pretty-urls
but not working ...
Someone help
http://localhost/react/Lara-react/public/admin/home
Does not work as the url does not search for index.php as your root path is http://localhost.
When you fire command php artisan serve command, the root of the app becomes
http://localhost/react/Lara-react/index.php hence all the routes are appended to root creating
http://localhost/react/Lara-react/public/index.php/admin/home which make the app work
On production you too define the root path of the project as /var/www/html/react/Lara-react/index.php.
So for development using php artisan serve command is helpful as it creates an simulated environment as production
1). Run common "gedit /etc/apache2/apache2.conf"
Alias /project_name /var/www/html/project_name/public/
<Directory /var/www/html/project_name/public>
AllowOverride All
Order allow,deny
allow from all
</Directory>
2). Add base url in 'project_name/public/.htaccess'
RewriteBase /project_name
3). finally run "service apache2 reastart"

Getting 404 by using Laravel routes - rewrite not working

I'm using Laravel-5 framework and created the following route in the routes/web.php:
Route::get('/test', function () {
return view('test');
});
After navigating to myapp.dev/test I get an Error 404:
Object not found! The requested URL was not found on this server. If you entered the URL manually please check your spelling and try again.
Navigating to myapp.dev/index.php/test works fine. So, looks like rewrite_mod is not working.
I'm using XAMP/Apache and rewrite_module is enabled in httpd.conf:
LoadModule rewrite_module modules/mod_rewrite.so
My larvavel's public folder contains a .htaccess file with following content:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
#DirectoryIndex index.php
# 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>
The httpd-vhost configuration looks like the following:
<VirtualHost *:80>
ServerAdmin my#mail.com
DocumentRoot "s:/_dev/myapp/public"
ServerName myapp.dev
<Directory "s:/_dev/myapp/public">
Allow from all
Require all granted
#Options Indexes
</Directory>
ErrorLog "logs/myapp.dev-error.log"
CustomLog "logs/myapp.dev-access.log" common
</VirtualHost>
Any ideas what I missed?
Thanks
I can not see any issues with our code however it could be a browser issue.
Have a look at this article which goes through the changes to browsers that cause issues with .dev domains.
https://medium.engineering/use-a-dev-domain-not-anymore-95219778e6fd

Laravel status not found, missing route

I'm trying to install Laravel on Wamp server and I'm getting this error:
{"status":"Not Found","error":true,"error_code":"missing_route","message":"Route not found.","data":[]}
Been searching for a while now and can't figure out what it is. I checked and triple checked if I added corectly my project in hosts file, if virtual host is set properly, also if rewrite module is activated and if .htaccess file in the public folder is as it should.
Hosts File:
127.0.0.1 app.my-site.com
Vhosts
<VirtualHost *:80>
ServerAdmin webmaster#my-site.com
DocumentRoot "C:/wamp/www/my-site/public"
ServerName app.my-site.com
<Directory "C:/wamp/www/my-site/public">
AllowOverride All
Order allow,deny
Allow from all
</Directory>
ErrorLog "logs/my-site-error.log"
CustomLog "logs/my-site-access.log" common
</VirtualHost>
.htaccess in public folder
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
Options +FollowSymLinks
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>
Can anybody suggest what could be wrong?

Resources