如何在家园机上显示Laravel路由,并在本地服务时显示相同的路径

问题描述 投票:0回答:1

我正试图从Homestead机器上为我的Laravel应用程序提供服务,方法如下。Homestead.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

我有以下路线。

Route::get('/', function () {
    return view('welcome');
});

Route::get('/hello-world', function () {
    return view('helloworld');
});

当我用git bash为网站服务时,我可以进入: http:/localhost:8000 来查看第一个URL。但是,如果我到 http:/exampleurl.test 我得到一个 No input file specified. 要访问欢迎页面,我必须在后面加上 /index.php 的URL。我一直没有搞清楚hello-world那个由家园运行时的URL是什么。

如何确保欢迎页的服务网址是 http://exampleurl.test 和hello-world可在 http:/exampleurl.testhello-world。

php laravel routes vagrant homestead
1个回答
0
投票

看起来重写规则在apache中没有正确配置,所以你需要仔细检查。

是的,你需要通过 index.php (也就是前台控制器),所以要访问hello-world,你需要访问 http://exampleurl.test/index.php/hello-world


0
投票

我是用以下方法解决的。

1.编辑了 .htaccess 档案在我 /public 的目录,并添加以下内容。

<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>
  1. 重新命名 server.php 在项目的根部,以 index.php

  2. 运行 vagrant reload --provision

© www.soinside.com 2019 - 2024. All rights reserved.