You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Laravel 8复制.htaccess到根目录后API路由无法访问问题

Laravel 8 API路由无法访问的解决办法

针对你在XAMPP部署Laravel 8后无法访问API路由的问题,可按以下步骤排查解决:

  • 确认API路由的访问路径
    Laravel的API路由默认带有api/前缀,访问时必须加上该前缀。比如routes/api.php中定义了Route::get('/test', function () { return response('API Test'); });,正确的访问地址应为http://localhost/myproject/api/test,而非直接访问/myproject/test。

  • 启用Apache的mod_rewrite模块
    确保XAMPP的Apache已开启重写模块:

    1. 打开XAMPP控制面板,点击Apache的Config按钮,选择httpd.conf
    2. 找到#LoadModule rewrite_module modules/mod_rewrite.so,删除行首的#注释符
    3. 重启Apache服务
  • 检查RouteServiceProvider配置
    打开app/Providers/RouteServiceProvider.php,确认API路由的分组配置是否正确:
    确保代码中存在类似如下的API路由分组设置,保证前缀和中间件正常应用:

    Route::prefix('api')
        ->middleware('api')
        ->namespace($this->namespace)
        ->group(base_path('routes/api.php'));
    
  • 清除路由和配置缓存
    进入项目根目录,执行以下命令清除缓存,确保路由规则生效:

    php artisan route:clear
    php artisan config:clear
    

内容的提问来源于stack exchange,提问作者Ahmad Attaroqqi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.16 22:42:01