Do you really mean that when users go to the second URL, it will be rewritten first? This can be done using
RewriteRule /blog/.+-(\d+)$ /blog/?pid=$1
301 URL- , .htaccess. , Apache mod_rewrite , , URL. PHP.
: , , , . RewriteMap, , Apache , , , PHP , , , , URL- . , - PHP.