对于移动PDF文件htaccess的规则?

编程入门 行业动态 更新时间:2024-10-24 08:25:00
本文介绍了对于移动PDF文件htaccess的规则?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我试过,我真的......我放弃。字preSS和htaccess的...哦疼痛。

I've tried, I really have...I give in. Wordpress and htaccess...oh the pain.

旧的静态网站有PDF,DOC,XLS和ZIP文件的所有根。我已经加载的所有的文件作为媒体项目,使他们都生活在/可湿性粉剂内容/上传。

Old static site has pdf, doc, xls and zip files all in the root. I've loaded all the files as media items so they all live in /wp-content/uploads.

我只是想捕捉任何404是.pdf文件重定向到文件夹上传。应该很容易,但我显然不是做正确的事情。 htaccess具有SOOOO许多标志和设置的东西太多会发生冲突或者我只是没有得到它。

I simply want to catch any 404 which is a .pdf file and redirect it to the upload folder. Should be easy but I'm clearly not doing something right. htaccess has soooo many flags and settings that something much be clashing or I'm just not "getting it".

RewriteEngine On # Catch incorrect case (must be a better way of doing this?) RewriteCond %{REQUEST_FILENAME} !-f RewriteRule (.*)\.JPG$ $1.jpg [L,R=301] RewriteCond %{REQUEST_FILENAME} !-f RewriteRule (.*)\.PNG$ $1.png [L,R=301] RewriteCond %{REQUEST_FILENAME} !-f RewriteRule (.*)\.GIF$ $1.gif [L,R=301] # BEGIN WordPress RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] # END WordPress # Start of my woes...what am I doing wrong? RewriteCond %{REQUEST_FILENAME} .*\.pdf [NC] #RewriteCond %{REQUEST_FILENAME} !\/wp-content\/uploads\/ RewriteRule ([^/]*\.pdf) /wp-content/uploads/$1 [NC,L,R=301] RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ([^\/]*.zip) /wp-content/uploads/$1 [L,R=301] RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ([^\/]*.xls) /wp-content/uploads/$1 [L,R=301] # For bonus points, is this the correct way to do this? Catch old reference to an old folder and move them on? RedirectMatch 301 /Graphic\sFiles/(.*\.jpg) /wp-content/uploads/$1 RedirectMatch 301 /Graphic\sFiles/(.*\.png) /wp-content/uploads/$1 RedirectMatch 301 /Graphic\sFiles/(.*\.gif) /wp-content/uploads/$1

我已经工作了:

  • httpd.apache/docs/current/rewrite/ flags.html
  • httpd.apache/docs/current/ MOD / mod_rewrite.html#重写规则
  • 的httpd.apache/docs/current/rewrite/remapping.html#fallback-resource
  • httpd.apache/docs/current/rewrite/flags.html
  • httpd.apache/docs/current/mod/mod_rewrite.html#rewriterule
  • httpd.apache/docs/current/rewrite/remapping.html#fallback-resource

SOOOO许多规则采取了我认为是一个简单的工作。我不是htaccess的大师也绝不会,我有足够的尊重那些虽然!

Soooo many rules to take in for what I thought was one simple job. I'm no htaccess guru and never will be, I have plenty of respect for those that are though!

感谢提前女士和男士的指针。

Thanks for any pointers in advance ladies and gents.

皮特

推荐答案

请问,如果你改变你的部分工作,它看起来像这样?

Does it work if you change your section to look like this?

RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_URI} !^/wp-content/uploads/ RewriteRule ([^/]*\.(pdf|zip|xls))$ /wp-content/uploads/$1 [NC,L,R=301]

第一个条件检查该请求是不存在的文件,二是要确保我们尚未重定向到上传目录(如果它不存在任),以及规则对任何PDF,zip或XLS相匹配。

First condition checks that the request is for a file that does not exist, the second is to make sure we've not already redirected to the uploads directory (in case it doesn't exist in there either), and the rule matches against either pdf, zip or xls.

更多推荐

对于移动PDF文件htaccess的规则?

本文发布于:2023-10-31 16:32:47,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1546646.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:规则   文件   PDF   htaccess

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!