为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

PHP
喵喔喔 2023-04-15 17:05:17
我正在尝试使用以下内容从 Homestead 机器为我的 Laravel 应用程序提供服务Homestead.yaml:name: homestead-fontysip: "192.168.10.12"memory: 2048cpus: 2provider: virtualboxauthorize: c:/Users/karin/.ssh/id_rsa.pubkeys:    - c:/Users/karin/.ssh/id_rsafolders:    - map: c:/Users/karin/Documents/uni/work/develop/laravel-forum/forum/      to: /home/vagrant/codesites:    - map: exampleurl.test      to: /home/vagrant/code/public      type: apache      php: "7.2"databases:    - forumfeatures:    - 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可用
查看完整描述

2 回答

?
蝴蝶刀刀

TA贡献1801条经验 获得超8个赞

我通过以下方式修复了它:


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>

server.php在项目根目录中重命名为index.php


跑了vagrant reload --provision


查看完整回答
反对 回复 2023-04-15
?
MM们

TA贡献1886条经验 获得超2个赞

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

是的,您需要通过index.php(也称为前端控制器)访问所有内容,因此要访问 hello-world,您需要访问http://exampleurl.test/index.php/hello-world


查看完整回答
反对 回复 2023-04-15
  • 2 回答
  • 0 关注
  • 79 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信