php icon indicating copy to clipboard operation
php copied to clipboard

Confusion in routing paths

Open swargaraj opened this issue 2 years ago • 3 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": "[email protected]"
    }
  },
  "routes": [
    {"src": "/(.*)",  "dest": "/index.php" }
  ]
}

swargaraj avatar Feb 26 '23 05:02 swargaraj

Hi @swargarajbhowmik.

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

{
  "functions": {
    "api/*.php": {
      "runtime": "[email protected]"
    }
  },
  "routes": [
    {"src": "/api/(.*)",  "dest": "/index.php" }
  ]
}

f3l1x avatar Feb 27 '23 13:02 f3l1x

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?

swargaraj avatar Feb 28 '23 07:02 swargaraj

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.

yokowasis avatar Apr 26 '23 14:04 yokowasis