我想将wp-content/uploads文件夹中的所有图像重写为wp-content/thumb文件夹中的thumbs.php文件,而无需更改url
I want to rewrite all the images in my wp-content/uploads folder to a thumbs.php file in wp-content/thumb folder without changing url
这是我在.htacccess中添加的内容
This is what I have added in my .htacccess
# BEGIN img <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} -f RewriteCond %{REQUEST_FILENAME} -d RewriteCond %{HTTP_USER_AGENT} !someweirdcrawler RewriteRule ^(wp-content/uploads/.+?)\.(jpe?g|png|gif|svg)$ /wp-content/thumbs/index.php?img_source=mywebsite/$1.$2 [L] </IfModule> # END img # other wordpress default stuff including wp-fastest-cache这是我想要实现的 访客访问我的网站或任何带有url之类的图片
This is what I want to achieve Visitors visit my site or any image with urls like
mywebsite/wp-content/uploads/2050/12/Hello-Dolly-1.0.0.1-words.jpg并且重写应该是
mywebsite/wp-content/thumbs/index.php?img_source=mywebsite/wp-content/uploads/2050/12/Hello-Dolly-1.0.0.1-words.jpg*对于那些可能认为... thumbs.php不是timthumb文件的人.我已经编写了自己的脚本来实现无损图像压缩
*For those who may think... thumbs.php is not timthumb file. I have written my own script for lossless image compression
更新: 它适用于我的其他网站..可能是什么问题?
UPDATE: Its working for my other site.. What could be the problem?
最终更新: 对于以后找到答案的人. 所以最后是因为我的WP FASTEST CACHE htaccess代码.刚刚删除了-d指令,并像一个符咒一样工作.但是我不再使用此代码,因为我找到了更好的选项.
FINAL UPDATE: For Those Who come to find answers Later. So Finally It was because of my WP FASTEST CACHE htaccess Code. Just removed the -d Directive and worked like a charm. But I am not using this code anymore because I have found better Options.
代码如下:
# BEGIN img <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} -f #show original images to Image crawler Like wordpress photon or google images. RewriteCond %{HTTP_USER_AGENT} !someweirdcrawler RewriteRule ^(wp-content/uploads/.+?)\.(jpe?g|png|gif|svg)$ /wp-content/thumbs/index.php?img_source=mywebsite/$1.$2 [L] </IfModule> # END img # other wordpress default stuff including wp-fastest-cache推荐答案
RewriteCond %{REQUEST_FILENAME} -f RewriteCond %{REQUEST_FILENAME} -d
所请求的映像永远不会既是文件又是目录,因此您的条件将永远不会匹配,并且请求也将不会被重写.对图像的有效请求应仅是文件,因此请删除第二个RewriteCond指令(-d目录检查).
The requested image is never going to be both a file and a directory, so your condition is never going to match and the request is never going to be rewritten. A valid request for an image should only be a file, so remove the second RewriteCond directive (-d directory check).
它可用于我的其他网站.
Its working for my other site..
您确定(代码相同)吗?
Are you sure (the code is the same)?
更多推荐
.htaccess将带有图像的URL从文件夹重写到php文件
发布评论