You should do this redirect on the page itself.
If the site is database driven it's a trivial few lines of code added to the PHP script.
If it's static .html pages, and you can invoke the PHP parser for .html pages (or rename the files to have a .php extension), you can use htaccess to detect the ID number in the URL request, rewrite that request to the internal file that will serve the content, then on the page itself compare the requested URL with what the URL should have been (define it at the top of the page) and redirect to that if it is different to the URL that was requested.
For this to work, you store the actual files on the hard drive with just the ID number as their name (and the .html or .php extension).
In htaccess:
RewriteRule ^([^-]+-)+([0-9]+)\.html$ /$2.php [L]
(or
/$2.html [L]
)
In the php or html file:
define (THIS_PAGE_CANONICAL, "name-of-page-44");
$requestedPage = _SERVER[ 'REQUEST_URI' ];
if ($requestedPage !== THIS_PAGE_CANONICAL) {
HEADER ('HTTP/1.1 301 Moved Permanently');
HEADER ('Location: http://www.example.com/' . THIS_PAGE_CANONICAL);
}
The above code goes at the very top of the file.
Remember this. URLs are used "out there" on the web. Filenames are used "here" inside the server. They are not at all the same thing, merely related by the server configuration.
In this case, the key is in using filenames that consist only of the ID number, the file having the URL definition at the top of the file and then comparing the requested URL with what it should have been. The rewrite connects the requested URL with the actual numbered file that will serve the content.
Get the rewrite working first. Try adding the redirect code after that. Try it with a test file, like
9999.php
or
9999.html
first.
The code above does NOT take into account that the files may be located in folders on your site. That's specific implementation detail for you to work through.