.htaccess - 白名单允许的 URL

.htaccess - whitelist allowed URLs

我有一个简单的 PHP 网络应用程序,我想限制 URL 用户可以访问几个 PHP 文件和一两个目录。任何未在 .htaccess 中列入白名单的 URL 都应被拒绝。

示例白名单:

/
/assets/*
index.php
profile.php
favicon.ico

这怎么可能最简单?

谢谢。

这就是我做类似事情的方式。特定文件,然后是文件夹。

RewriteCond  !^(index\.php|robots\.txt|style\.css|sitemap\.xml)
RewriteCond %{REQUEST_URI}  !/img/ [NC]
RewriteRule ^(.*)$ - [F]

根 .htaccess 中的一个简单 RewriteRule 即可:

RewriteEngine On

RewriteRule !^(index\.php|profile\.php|favicon\.ico|assets/.*)?$ - [F,NC]