How to use URL structure to call PHP code

I assume alan-walker is just an example and this could be any string of this form. (Or is it literally just “alan-walker”, as in you example?)

You can do this with a single RewriteRule in .htaccess before the WordPress front-controller. For example:

RewriteRule ^directory/([a-z-]+)$ /directory.php?s=$1 [L]

This will rewrite /directory/<something> to /directory.php?s=<something>,
where <something> consists of one or more of the characters a to z and -.


…instead of calling alan-walker.php

This would only happen if you have MultiViews enabled. And only if alan-walker.php existed as a real file (which you say it doesn’t). It is not enabled by default, however, if it is, it can be disabled by calling the following at the top of your .htaccess file:

Options -MultiViews