I'm saving some pdfs into a folder with mpdf, the urls of pdfs are like this:
https://example.com/wp-content/themes/mysitetheme/invoices/invoice_8937.pdf
I want that if someone open this url it will show a shorter version like this:
https://example.com/invoice_8937.pdf
how can I obtain this result using add_rewrite_rule() and apache web server?
UPDATE as suggested I changed the code that generates pdfs in a way that are not stored in a local folder, but are generated everytime when visiting the url with a specified id parameter like this
https://example.com/wp-content/themes/mysitetheme/includes/mpdf/invoice?id=8937.pdf
so now the correct rewrite rule is
/**
* Rewrite rules
*/
add_action( 'init', function() {
add_rewrite_rule( '^example.com/invoice_([0-9]+).pdf$', '/wp-content/themes/mysitetheme/includes/mpdf/invoice.php?id=$1', 'top' );
} );
mpdf
? – Tom J Nowell♦ Nov 10 '20 at 1:03