首页 > 解决方案 > 不要将重写规则应用于特定的文件扩展名

问题描述

我有一个 htaccess 可以在特定情况下重写一些 url。

RewriteEngine On
RewriteRule \.php$ - [L,NC]
RewriteRule ^(?:favicon\.ico|(?:index|custom500|custom404)\.html)$ - [L,NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .+ index.php?source=$0 [L,QSA]

在里面我有一个规则,防止 index.html、custom404.html、custom500.php 和 favicon.ico 被包含在重写中。现在我正在尝试为任何以 pdf 或 jpg 扩展名结尾的文件添加相同的逻辑。所以我尝试将pdf扩展名添加到排除列表

RewriteRule ^(?:favicon\.ico|(?:index|custom500|custom404)\.html|?:\*\.pdf)$ - [L,NC]

但是 apache 无论如何都会将此文件作为index.php?source=myfile.pdf 如何将 .pdf 和 .jpg 正确添加到此列表中?

标签: apache.htaccessapache2.4

解决方案


推荐阅读