How do I make the same variable available to all my theme files?
You would have to add a cache context:

$variables['#cache']['contexts'][] = 'url.path';


Now you cache for each relative path a different version of the template.

However, it is not a good idea to add this context to all templates. Only add it to those templates you intend to use the variable, otherwise you fill up your cache with a lot of useless variations:

function mytheme_preprocess(&amp;$variables, $hook) {
  if (in_array($hook, ['foo', 'bar'])) {
    $variables['#cache']['contexts'][] = 'url.path';
    // add variables depending on the relative url
  }
}