Is it possible to hook_form_alter by path? I have a basic hook_form_alter working but the issue is I cannot do it by form id as the id might be different in various environments, i.e. local, dev, production. So the usual method of altering by targeting a form ID is not ideal then.

I figured I could do this by path (as that won't change) but none of the usual methods work. I'd like to keep this in code so that's why I'm not simply changing the UI for this setting. 

Here's my basic alter which works:

function MYMODULE_form_alter(&amp;$form, &amp;$form_state, $form_id) {
  $form['submitted']['donation']['amount']['#title'] = t('My new title');
}


However, if I do this, it does not work:

function MYMODULE_form_alter(&amp;$form, &amp;$form_state, $form_id, $host) {
  $host = $_SERVER['HTTP_HOST'];
  if ($host == "m.local.dev/donate" or  $host == "m.live.com/donate") {
  $form['submitted']['donation']['amount']['#title'] = t('My new title');
   }
}


I'm guessing what I'm trying to do is not even possible and therefore I'll try to figure out a different method.
I think you should use  $_SERVER['HTTP_HOST'] . request_uri();

This will give you the complete path. 

So your code should be 

function MYMODULE_form_alter(&amp;$form, &amp;$form_state, $form_id, $host) {
  $host = $_SERVER['HTTP_HOST'] . request_uri();
  if ($host == "m.local.dev/donate" or  $host == "m.live.com/donate") {
  $form['submitted']['donation']['amount']['#title'] = t('My new title');
   }
}