Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我对 htaccess 文件和正则表达式异常有点迷失......我怎样才能让 htaccess 拒绝访问类似的文件:#.jpg 其中 # 是一位或多位数字?
1.jpg ->deny 25.jpg ->deny 74_thumb ->allow 22_400 -> allow 14254.jpg ->deny
我正在寻找正确的正则表达式语法来将数字仅与另一个文件名区分开来。我发现这可以通过 htaccess 文件和重写条件来完成,或者通过异常拒绝但找不到具体示例来说明如何完成。
通过启用 mod_rewrite 和 .htaccess httpd.conf,然后将此代码放在您.htaccess的DOCUMENT_ROOT目录下:
httpd.conf
.htaccess
DOCUMENT_ROOT
RewriteEngine On RewriteRule (^|/)[0-9]+\.jpe?g$ - [F,NC]