I currently have a PHP project that I'm transferring over to Vercel (for the free hosting). I'm struggling to load any files outside of the index.php file, I've created a simpler project for the purposes of this question, however I'm still getting the same errors.
This is my file structure:
MyPHPProject
- index.php
- vercel.json
- api
- index.php
- another-page
- index.php
Below is my vercel.json file:
{
"functions": {
"api/*.php": {
"runtime": "vercel-php@0.4.0"
}
},
"routes": [
{ "src": "/(.*)", "dest": "/api/index.php" }
]
}
This is my api/index.php file:
<?php include __DIR__ . '/../index.php'; ?>
This is my ```index.php`` file (in main route):
<html>
<head></head>
<body>
<div class="testbackground">
<a href="/another-page">Another Page</a>
<h1>Hello there!</h1>
<?php include __DIR__ . '/another-page/index.php'; ?>
</div>
</body>
</html>
My another-page/index.php file is:
<h1>This better work</h1>
When I go to my server (https://testingphp.vercel.app/) I get the following:
Another Page
Hello there!
This better work
However when I go to https://testingphp.vercel.app/another-page, it doesn't load the correct index.php file.
Any help is much appreciated.