I have disabled "Organize my uploads into month and year-based folders".
The links to my PDF files were of the form:
.pdf
And now they are:
.pdf
Is it possible to redirect all my .../YEAR/MONTH/...
PDF URLs to the new URL without the YEAR/MONTH/
part?
I have disabled "Organize my uploads into month and year-based folders".
The links to my PDF files were of the form:
https://www.example/wp-content/uploads/2018/03/document.pdf
And now they are:
https://www.example/wp-content/uploads/document.pdf
Is it possible to redirect all my .../YEAR/MONTH/...
PDF URLs to the new URL without the YEAR/MONTH/
part?
1 Answer
Reset to default 1The .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]
</IfModule>
# 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]
</IfModule>
# END WordPress
/year/month/
directory. – Fayaz Commented Aug 29, 2018 at 11:14