mod_rewrite 匹配非图像文件
我有以下重写规则
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} -s
RewriteRule ^wp-content/uploads/(.*)$ dl-file.php?file=$1 [QSA,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
,其中对 wp-content/uploads 的每个请求都由 dl-file.php 处理,以检查用户是否已登录。
我仍然需要具有该功能,但授予对图像的免费访问权限(png|) jpg|gif|jpeg) 我有点迷失了,我不知道如何修改重写规则来检查任何不是图像的文件。
I have the following rewrite rules
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} -s
RewriteRule ^wp-content/uploads/(.*)$ dl-file.php?file=$1 [QSA,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Where every request to the wp-content/uploads its handled by dl-file.php in order to check if user its logged in.
I need to still have that functionality but grant free access to images (png|jpg|gif|jpeg)
Im a bit lost i dont know how to modify the rewrite rule to check any file that its no an image.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在重写 dl-file.php 的规则之前,您可以插入更具体的图像规则:
这三个规则中的每一个都具有相同的结构,我将解释第一个:
匹配上传中以 .png 结尾的任何内容
使用括号将整个路径保存到变量 $1 中。
规则的右侧给出了这个变量,所以如果你看
在一个特定的 url 中,这可以归结为:
末尾的 L 告诉重写引擎这是要应用的最后一条规则。
因此,如果匹配,重写过程将在此结束,您的 png 图像将被提供。
before the rule that rewrites to dl-file.php you could insert more specific rules for images:
Each of the three rules has the same structure, I'll explain the first one:
match anything in uploads that ends in .png
with the brackets you save the whole path into a variable $1.
the right hand side of the rule gives this variable, so if you look
at one specific url this boils down to:
the L at the end tells the rewrite engine that this is the last rule to apply.
so if it matches, the rewriting process ends here, your png-image is served.