Getting 404 by using Laravel routes - rewrite not working - laravel

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

Related

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">

Laravel - set /public as root on LAMP stack

I'm trying to deploy a Laravel App on a LAMP stack although I am having trouble setting the document root as /public. I've looked at several answers on here already for similar problems but am yet to find my problem or a solution. I ideally I want to do it through the Apache web server and not modify any Laravel files.
I copied the default .conf file a change it to the following using sudo nano /etc/apache2/sites-available/subdomain.website.com.conf
<VirtualHost *:80>
ServerAdmin email#gmail.com
ServerName subdomain.website.com
ServerAlias www.subdomain.website.com
DocumentRoot /var/www/subdomain.website.com/public_html/public
<Directory /var/www/subdomain.website.com/public_html/public/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<IfModule mod_dir.c>
DirectoryIndex index.php index.pl index.cgi index.html index.xhtml index.htm
</IfModule>
RewriteEngine on
RewriteCond %{SERVER_NAME} =www.subdomain.website.com [OR]
RewriteCond %{SERVER_NAME} =subdomain.website.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
After the I ran the following commands in this order.
sudo a2ensite subdomain.website.com.conf
sudo a2enmod rewrite
sudo systemctl restart apache2
sudo service apache2 restart
I cleared cookies, did a hard refresh and it hasn't worked. I still have to go to https://subdomain.website.com/public to view the website. Is there anything I have missed or anything I can do find out what the problem may be?
The .htaccess file in the /public folder contains the following
<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>
This virtualhost is for http:// (Port 80). You have a rewrite rule that redirects to https:// as soon as it hits this virtualhost.
RewriteEngine on
RewriteCond %{SERVER_NAME} =www.subdomain.website.com [OR]
RewriteCond %{SERVER_NAME} =subdomain.website.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
Therefore, you need to apply your changes to the other virtualhost that is serving this domain from https:// (Port 443).

Lumen routes not working

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>

laravel 5 error 500 fresh install

Hello so i got back to laravel recently and want to put on my webserver but i get error 500 from a fresh installed laravel. though i havent done any modifying the code in the framework would be sweet if anyone has an idea whats going on in the changes to laravel from those settings i provide
error 500 and no logs in apache nor laravel
thanks in advance
htaccess file.
<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}]
conf file
ServerName domain.com
DocumentRoot /var/www/laravel/public/
<Directory /var/www/laravel/public/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
If you're using Linux os,you'll need to do the following
cd to_the_root_of_project - i.e. cd /var/www/html/LaravelProject
sudo chmod guo+w -R storage/

How to use Laravel an OSX Mavericks and MAMP 5.4.14 using an alias?

I am trying out Laravel for the first time and have installed it on my Mac (OSX Mavericks) along with an existing install of MAMP 5.4.14 (PHP 5.4.14, Apache 2). I have various other projects (CakePHP) installed on MAMP and have no issues serving the files from aliased directories. However Laravel doesn't seem to like the config it came with or what I used for CakePHP and I haven't found a solution yet.
In my Apache config I have this defined as my alias:
Alias /laravel/ "/Users/user1/Documents/Web Development/laravel/public/“
<Directory "/Users/user1/Documents/Web Development/laravel/public”>
Options +Indexes +MultiViews +FollowSymLinks
AllowOverride All
Require all granted
</Directory>
and in the Laravel public folder I have this in the htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /laravel/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
Unfortunately all I get is a standard Apache 403 error.
[Sat Mar 22 17:29:38.408215 2014] [authz_core:error] [pid 31418] [client ::1:51107] AH01630: client denied by server configuration: /Users/user1/Documents/Web Development/laravel/public/\xe2\x80\x9c
Can anyone offer some hints as to what I am overlooking? Thanks
Edit - additional info
Chmod'd the entire laravel directory to 777 didn't help
Laravel app.php file has
'url' => 'http://localhost:8080/laravel',
I ran the internal php server and it worked correctly (php artisan serve), although it threw an exception on base64_decode
Also tried the default htaccess
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteBase /laravel/
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
Well, I should have noticed the \xe2\x80\x9c in the apache message, which is the dreaded curly quotes. Copying and pasting between editors managed to muck up my config files. Here is the final config just for reference:
Apache alias conf:
Alias /laravel/ "/Users/user1/Documents/Web Development/laravel/public/"
Alias /laravel "/Users/user1/Documents/Web Development/laravel/public"
<Directory "/Users/user1/Documents/Web Development/laravel/public">
Options +Indexes +MultiViews +FollowSymLinks
AllowOverride All
Require all granted
</Directory>
htaccess file in my laravel project is the default
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteBase /laravel/
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
and I can access it at
http://localhost:8080/laravel/
Hope this helps someone else!

Resources