regex - How to remove "YEARMONTH" from uploads URL & redirect old URL to the new form?

I have disabled "Organize my uploads into month and year-based folders".The links to my PDF files were of the

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?

Share Improve this question edited Aug 29, 2018 at 17:09 Fayaz 9,0172 gold badges33 silver badges51 bronze badges asked Aug 29, 2018 at 11:10 HPetersenHPetersen 213 bronze badges 2
  • 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 Commented Aug 29, 2018 at 11:14
  • 1 I have delete them manually, so thats under control. Its more for pages that is indexed on Google & Bing. – HPetersen Commented Aug 29, 2018 at 11:34
Add a comment  | 

1 Answer 1

Reset to default 1

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]
</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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745381571a4625251.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信