You can't use htaccess to do this for you. It's possible to use a RewriteMap
that you can define in your server config (can't define it in htaccess file), but it's far easier if you just do this in your locationProfile.php
script.
You can detect if the request is made with the query string using the REQUEST_URI value:
if ( $_SERVER['REQUEST_URI'] == '/locations/locationProfile.php' &&
isset($_GET['locationID'])) {
// go into DB and extract the location name then redirect
header('Location: /locations/' . $location-name);
}
Then in your htaccess file in your document root):
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^locations/([^/]+)$ /locations/locationProfile.php?locationName=$1 [L,QSA]
And finally, make your php script look for the locationName
parameter and server the proper page based on that instead of the ID.