I'm currently using a plugin that generates a PDF for customers but the URL is way too long. For eg - https://www.mywebsite.com/wp-content/uploads/pdfuploads/666666.pdf. Here's the specific code from the plugin relating to this:
$upload = wp_upload_dir();
$upload_dir = $upload['basedir'];
$upload_dir = $upload_dir . '/pdfuploads';
if (! is_dir($upload_dir)) {
mkdir( $upload_dir, 0755 );
$file = fopen($upload_dir.'/index.html',"wb");
echo fwrite($file,"Silence is golden.");
fclose($file);
}
The PDF then generates in:
=> get_home_url().'/wp-content/uploads/pdfuploads/'
$attachments[0] = $upload_dir.'/pdfuploads/'
I want to shorten this URL so it reads something like - https://www.mywebsite.com/pdfs/666666.pdf. I tried adding RewriteRule ^wp-content/uploads/pdfuploads/(.*)$ /pdfs/$1 [R=301,NC,L] to htaccess but that didn't move the files over. Is there a quick fix for this via htaccess or functions? Otherwise, if I need to edit the plugin's PHP files myself, what do I need to change in the above code?
.htaccess
file? The rewrite rule works, right? Because to actually move the files, that's a pretty complex task and I can't help you with that. But if the rewrite rule works, then I can tell you which files you can edit.http://example.com/pdfs/filename.pdf
, you get the correct PDF file.