文件只有PHP可读?

我想让我的服务器上的文件可以被PHP读取,但不能直接通过浏览器访问。 说我的Apache安装的根是/ apache。 我希望PHP能够获得/apache/1.txt的文本,但不允许用户去domain.tld/1.txt和查看内容。 我仍然希望能够通过FTP / SFTP无文件读/写文件。

什么是propper chmodstring呢? 642似乎可能,但我不知道如何PHP访问该文件。

使用.htaccessapacheconfiguration将所有到/1.txt请求redirect到别的东西。 所以,如果有人尝试访问domain.tld/1.txt ,它将redirect。

编辑

例:

 suku@ubuntu-vm:/var/www/html$ grep info.php /etc/apache2/sites-available/default RedirectMatch ^/info.php /html/index.html suku@ubuntu-vm:/var/www/html$ sudo cat ../info.php <?php phpinfo(); ?> suku@ubuntu-vm:/var/www/html$ cat index.html You redirected to here becuase you tried to access localhost/info.php suku@ubuntu-vm:/var/www/html$ pwd /var/www/html suku@ubuntu-vm:/var/www/html$ links http://localhost/info.php -dump You redirected to here becuase you tried to access localhost/info.php suku@ubuntu-vm:/var/www/html$ cd .. suku@ubuntu-vm:/var/www$ ls -l info.php -rw-r----- 1 www-data www-data 20 Jan 12 11:25 info.php