0

I am used to SEND all sorts of requests to 'foreign' URLs or to my Website Server URL and receive responses and such.

And thus, i am used to receive requests as well.

BUT

Only if it targets a PHP file like so : http://www.example.com/file.php

In order for a core part of my future website feature to work, i need to be able to listen to a GET request made to a "blank" url like so : http://www.example.com/blank/?key1=value1&key2=value2

Is there a way to 'run' a PHP script whenever this URL is called ? Even if it is not targeted directly in the request ? Any other script ?

I'm kinda ignorant when it comes to server-side mecanisms.

EDIT :

I have tried to create a file.PHP with the following :

$key1 = $_GET['key1'];
$key2 = $_GET['key2'];
echo "$key1 and $key2";

but response is 403 (forbidden)


EDIT2 : To my moderator : the question linked is not the exact same question as mine. He asks to hide the file extension, i ask how to target a directory. Even if the answer has the same source (htaccess) it is not the same thought process. Further more, my title explicitely mentions requests (hence the tags API and ESI) and not only the php subject.

Bo. Ga.
  • 138
  • 1
  • 4
  • 12

1 Answers1

1

In general: Yes but how to do it exactly depends on your web server software. For Apache for example, you can use a .htaccess file to create rewrite rules to make paths matching a certain pattern (e.g. /blank/<whatever>) behave as if they were another path (e.g. /blank.php).

But in your case where you actually have /blank/ as "directory", there is an even simpler way: Put an index.php file into the directory.

It's an almost universal convention that if a directory is specified in the URL (without specific filename), the server will look for an index.php file (or index.html, but your question was about PHP in particular) in the directory and direct the request there.

CherryDT
  • 25,571
  • 5
  • 49
  • 74
  • It works perfectly ! (with echo) I am so glad i was going down this path with htaccess, a couple more days and i would've found the solution. ahah :D Thank you so much for saving those for me <3 – Bo. Ga. Apr 19 '21 at 20:30