Question

A client had his PDF files uploaded to the CMS' root over month. I'ld like to move all PDFs into a new subfolder to keep the root clean. Problem now is they absolute linked these PDFs in many articles. Is there a way I can redirect all (and only) links to a root PDF to their new destination?

Additionally, I tried do my homeworks but couldn't find a comprehensive guide about .htaccess and ask you to share the best gem from you bookmarks.

Was it helpful?

Solution

You can use this rule in your root .htaccess:

RewriteEngine on

RewriteRule ^([^./]+\.pdf)$ /subfolder/$1 [L,NC,R=301]

OTHER TIPS

This should do it:

RewriteEngine on
RewriteBase /
RewriteRule ^([^/]*?).pdf$ newpath/$1.pdf
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top