vercel-community / php

🐘 PHP Runtime for ▲ Vercel Serverless Functions (support 7.4-8.3)

Home Page:https://php.vercel.app

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Confusion in routing paths

swargaraj opened this issue · comments

Hey There, I'm actually new to Vercel. I'm confused how to route between different paths.

I am using standalone PHP, not any framework like Laravel.

I have the project structure like:

/api/v1.php
/api/v2.php
/data/file.txt
/assets/style.css
/assets/script.js
index.html

I want users to access the website like:

.com/ (here does the index.html)
.com/assets/style.css
.com/assets/script.js
.com/data/file.txt
.com/api/v1
.com/api/v2

Can anybody help me to make that vercel.json for it 🙏

The current structure is this:

{
  "functions": {
    "api/*.php": {
      "runtime": "vercel-php@0.5.2"
    }
  },
  "routes": [
    {"src": "/(.*)",  "dest": "/index.php" }
  ]
}

Hi @swargarajbhowmik.

I think you are looking for something like that. Just prefix route with api and it should work.

{
  "functions": {
    "api/*.php": {
      "runtime": "vercel-php@0.5.2"
    }
  },
  "routes": [
    {"src": "/api/(.*)",  "dest": "/index.php" }
  ]
}

Hi There, Thanks for replying..
No, I don't want like that.
I just want to point everything containing inside the directory /api/* to point towards .com/*
How can I implement that?

Hi There, Thanks for replying.. No, I don't want like that. I just want to point everything containing inside the directory /api/* to point towards .com/* How can I implement that?

You can't do that. Php is server side. And server side only get to run on API folder on vercel.