Mod_Rewrite - 按文件类型过滤

Mod_Rewrite - Filtering by file type

我有一个 Wordpress 博客,其目录结构包含一个 "sermons" 文件夹。该目录包含与给定布道相关的 mp3 和 pdf 文件。

我现在也有一个友好的url布道,叫做"sermons"这显然会引起问题。

有没有办法过滤结果,以便如果请求的文件是 pdf 或 mp3,它会访问文件系统,但在其他情况下,它会由管理其他 WordPress 页面的 htaccess 中的规则处理?

这是我目前拥有的:

 AddHandler application/x-httpd-php54 .php

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{REQUEST_URI} ^/sermons/(.+)/*\.(mp3|pdf)$ [NC]
RewriteRule ^(.*)$ - [L]

RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

基于假设,因为您没有 post 当前代码。您应该能够在其他规则的顶部使用它。

RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{REQUEST_URI} ^/sermons/(.+)/*\.(mp3|pdf)$ [NC]
RewriteRule ^(.*)$ - [L]