对于“config.php”这样的指定文件,我需要返回404错误。我如何在Apache中使用“.htaccess”来实现它呢?而在没有htaccess的nginx?谢谢。
发布于 2020-06-07 09:26:41
NGINX:
location = /config.php {
return 404;
}
发布于 2020-06-07 19:24:24
您不需要在Apache中使用.htaccess
,实际上建议将它作为一个最后手段。同样,只有在必要时才应该使用mod_rewrite:何时不使用mod_重写。
您可以同时使用Redirect
和RedirectMatch
从mod_alias返回404:
Redirect 404 /config.php
RedirectMatch 404 ^/config.php$
您可以将它们直接放置在您的服务器配置中,或者放在您的虚拟主机中。
<VirtualHost *:80>
ServerName www.example.com
DocumentRoot "/var/www/example.com"
Redirect 404 /config.php
</VirtualHost>
发布于 2020-06-07 11:45:34
Apache上的.htaccess
(使用mod_rewrite):
RewriteEngine On
RewriteRule ^config\.php$ - [R=404]
在文档根目录中假设/config.php
。
https://serverfault.com/questions/1020410
复制相似问题