php - How to display Laravel route the same on a homestead machine and when served locally
Get the solution ↓↓↓I am trying to serve my Laravel application from a Homestead machine with the followingHomestead.yaml
:
name: homestead-fontys
ip: "192.168.10.12"
memory: 2048
cpus: 2
provider: virtualbox
authorize: c:/Users/karin/.ssh/id_rsa.pub
keys:
- c:/Users/karin/.ssh/id_rsa
folders:
- map: c:/Users/karin/Documents/uni/work/develop/laravel-forum/forum/
to: /home/vagrant/code
sites:
- map: exampleurl.test
to: /home/vagrant/code/public
type: apache
php: "7.2"
databases:
- forum
features:
- mariadb: false
- ohmyzsh: false
- webdriver: false
I have the following routes:
Route::get('/', function () {
return view('welcome');
});
Route::get('/hello-world', function () {
return view('helloworld');
});
When I serve the website from git bash I can go to http://localhost:8000/ to view the first URL. However, if I go to http://exampleurl.test I get aNo input file specified.
To access the welcome page I have to append/index.php
to the URL. I have not figured out what the URL is for the /hello-world one when run by Homestead.
How can I make sure that the welcome page is served on the URLhttp://exampleurl.test
and hello-world is available at http://exampleurl.test/hello-world
Answer
Solution:
It looks like re-write rules are not properly configured in apache, so you need to double-check that.
Yes, you will need to access everything throughindex.php
(which is also called the front controller), so to access hello-world you'll need to visithttp://exampleurl.test/index.php/hello-world
Answer
Solution:
I fixed it the following way:
1.edited the.htaccess
file in my/public
directory with the following:
<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]
</IfModule>
Renamed
server.php
in the project root toindex.php
ran
vagrant reload --provision
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: unable to determine current zabbix database version: the table "dbversion" was not found.
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.