如何在宅基地机器上和本地服务时显示相同的 Laravel 路由

我正在尝试使用以下内容从 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.To access the welcome page I have to append /index.phpto the URL。当由 Homestead 运行时,我还没有弄清楚 /hello-world 的 URL 是什么。


我怎样才能确保欢迎页面在 URL 上提供并且 hello-world 在http://exampleurl.test/hello-worldhttp://exampleurl.test可用


喵喔喔
浏览 82回答 2
2回答

蝴蝶刀刀

我通过以下方式修复了它:1.使用以下内容编辑.htaccess我目录中的文件:/public<IfModule mod_rewrite.c><IfModule mod_negotiation.c>&nbsp; &nbsp; Options -MultiViews</IfModule>RewriteEngine On# Redirect Trailing Slashes If Not A Folder...RewriteCond %{REQUEST_FILENAME} !-dRewriteRule ^(.*)/$ /$1 [L,R=301]# Handle Front Controller...RewriteCond %{REQUEST_FILENAME} !-dRewriteCond %{REQUEST_FILENAME} !-fRewriteRule ^ index.php [L]</IfModule>server.php在项目根目录中重命名为index.php跑了vagrant reload --provision

MM们

看起来重写规则没有在 apache 中正确配置,所以你需要仔细检查一下。是的,您需要通过index.php(也称为前端控制器)访问所有内容,因此要访问 hello-world,您需要访问http://exampleurl.test/index.php/hello-world
打开App,查看更多内容
随时随地看视频慕课网APP