I have disabled "Organize my uploads into month and year-based folders".

The links to my PDF files were of the form:


And now they are:


Is it possible to redirect all my .../YEAR/MONTH/... PDF URLs to the new URL without the YEAR/MONTH/ part?

  • It's definitely possible, but you'll be in trouble when there are multiple documents with the same name within different /year/month/ directory. – Fayaz Aug 29 '18 at 11:14
  • 1
    I have delete them manually, so thats under control. Its more for pages that is indexed on Google & Bing. – HPetersen Aug 29 '18 at 11:34

The .htaccess RewriteRule to rewrite only .pdf to not use /year/month/ can look like this

RewriteRule ^wp-content/uploads/([0-9]+)/([0-9]+)/(.+?)$ /wp-content/uploads/$3.pdf [L,R=301]

You should add this prior to WordPress' rules, so it will be evaluated before them, resulting in a .htaccess file like this

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^wp-content/uploads/([0-9]+)/([0-9]+)/(.+?)\.pdf$ /wp-content/uploads/$3.pdf [L,R=301]

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress
| improve this answer | |
  • Nice ! Its almost there. It shall only be PDF files, not images and videos. Is that possible ? – HPetersen Aug 29 '18 at 11:32
  • @HPetersen I've updated the answer – kero Aug 29 '18 at 12:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.