Skip to content
Advertisement

How to set up PHP script to receive requests to non-existent directories in a directory?

Say, if I have a dir directory in a root directory on the server with index.php file in it, can I set up that index.php to be called for any of the following links:

https://example.com/dir/
https://example.com/dir/something
https://example.com/dir/something_else

Sorry, I’m not sure how to call this, but basically so that the last segment of the URL was passed into index.php script that is in the example.com/dir/.

PS. My website is hosted on a shared web hosting platform.

Advertisement

Answer

Instead of having an index.php in every folder, you can leverage FallbackResource by creating an .htaccess file and putting in the following:

FallbackResource /index.php

Then, you can parse $_SERVER['REQUEST_URI'], and do whatever you want with it.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement