php - htaccess 阻止访问除 style.php 文件之外的 php 文件

标签 php css .htaccess redirect url-rewriting

在我的主 .htaccess 文件中,我有以下规则:

RewriteCond %{THE_REQUEST} /.+?\.php[\s?] [NC]
RewriteRule ^ - [F]

防止直接访问 php 文件(使用 seo 友好的 url 调用)。

现在我正在开发一个名为 with 的动态 CSS 代码

<link rel="stylesheet" href="theme1/style.php">

有办法允许 style.php 文件并阻止所有其他 .php 文件吗?

PS:也在我的“theme1”目录中,我有另一个带有以下代码的htaccess:

<Files *.php>
order allow,deny
deny from all
satisfy all
</Files>

如何编辑这 2 个 .htaccess 文件以仅允许 style.php 文件?

最佳答案

您可以使用否定前瞻来跳过该 php 文件:

RewriteCond %{THE_REQUEST} /(?!.*?style\.php).+?\.php[\s?] [NC]
RewriteRule ^ - [F]

关于php - htaccess 阻止访问除 style.php 文件之外的 php 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27356423/

相关文章:

php - .htaccess 与 ^(.*)$ index.php/$1 给出 "No input file specified"

php - 在快速结账时通过 PayPal 退款

php - 如何在不检查每个值(如果存在)的情况下防止重复记录

php - TCPDF - 将复选框设置为只读

css - react : Relative positioning of two divs within div

php - 使用 mod_rewrite 删除 .php 扩展并同时清理 GET url

php - 更改 Apache 默认索引文件

php - 使用 header () 时 localhost 重定向你太多次

jquery - 好吧,这很愚蠢 : overlays and z-indexes

html - 使文本在响应图像中保持在同一位置