Using router in php

How can I use router in php? I tried the following code:
$parsed_url = parse_url($_SERVER['REQUEST_URI'])['path'];
echo $parsed_url;
print_r($_SERVER);

if ($parsed_url == '/test/hihi/') {
echo 'hihi';
}
$parsed_url = parse_url($_SERVER['REQUEST_URI'])['path'];
echo $parsed_url;
print_r($_SERVER);

if ($parsed_url == '/test/hihi/') {
echo 'hihi';
}
It return error 404 instead of hihi
32 Replies
Percy
Percy12mo ago
Project ID: N/A
Brody
Brody12mo ago
https://nixpacks.com/docs/providers/php
If a NIXPACKS_PHP_FALLBACK_PATH variable is passed, that will be used as a fallback for the server - for instance, if your app uses index.php as a router, you would set this variable to /index.php
Croissant
CroissantOP12mo ago
Thanks, is the link correct?
Brody
Brody12mo ago
lmao nope, my bad fixed
Croissant
CroissantOP12mo ago
Thanks! I tried using the template and I got this error message: nginx: [emerg] directive "include" is not terminated by ";" in /app/nginx.conf:11 which points to include $!{nginx}/conf/mime.types; I think $!{nginx} is causing issue
Brody
Brody12mo ago
did you name the conf file correctly as it is named in railways github? but also, you don't need to modify it to achieve what you have asked
Croissant
CroissantOP12mo ago
Where can I get the conf file? Because I want to fallback at different php file for different directory
Brody
Brody12mo ago
did you read this message?
Croissant
CroissantOP12mo ago
Yes, I only copy this file and put it on my root directory https://github.com/railwayapp/nixpacks/blob/main/src/providers/php/nginx.template.conf
GitHub
nixpacks/src/providers/php/nginx.template.conf at main · railwayapp...
App source + Nix packages + Docker = Image. Contribute to railwayapp/nixpacks development by creating an account on GitHub.
Croissant
CroissantOP12mo ago
Is there additional files that I have to copy?
Brody
Brody12mo ago
my original message says nothing about a conf file, please read the message
Croissant
CroissantOP12mo ago
I understand but what I am trying to achieve is /test/anything will fallback to /test/index.php
Brody
Brody12mo ago
that is exactly what my message explains how to do I'm not understanding where the confusion is coming from
Croissant
CroissantOP12mo ago
From my understanding, setting NIXPACKS_PHP_FALLBACK_PATH means everything will failback to a file if it's not found in the server right?
Brody
Brody12mo ago
correct
Croissant
CroissantOP12mo ago
However, I only want certain directory to failback to the file, not everything
Brody
Brody12mo ago
that was not clearly communicated to me until just now
Croissant
CroissantOP12mo ago
That's on me, my bad
Brody
Brody12mo ago
show me your conf file how you have it in your repo
Croissant
CroissantOP12mo ago
I just copy this configuration file from the example repo and try to deploy it, however I couldn't get it work normally. https://github.com/railwayapp/nixpacks/blob/main/src/providers/php/nginx.template.conf The error I got is nginx: [emerg] directive "include" is not terminated by ";" in /app/nginx.conf:11
GitHub
nixpacks/src/providers/php/nginx.template.conf at main · railwayapp...
App source + Nix packages + Docker = Image. Contribute to railwayapp/nixpacks development by creating an account on GitHub.
Brody
Brody12mo ago
please show me your conf file how you have it in your repo
Croissant
CroissantOP12mo ago
No description
Croissant
CroissantOP12mo ago
No description
Croissant
CroissantOP12mo ago
It's in the root directory
Brody
Brody12mo ago
you have changed it's name
Croissant
CroissantOP12mo ago
yes, I changed it to nginx.conf
Brody
Brody12mo ago
why though?
Croissant
CroissantOP12mo ago
It mentioned it's supported
No description
Brody
Brody12mo ago
yes but why would you rename it?
Croissant
CroissantOP12mo ago
Just to try out if it will work
Brody
Brody12mo ago
it's not going to work if it's named incorrectly
Croissant
CroissantOP12mo ago
I have renamed it to nginx.template.conf I think it works
Want results from more Discord servers?
Add your server