如何在不编辑 .htaccess 文件的情况下重定向非 php 文件的 URL?
所以基本上我需要一种方法来获取我的服务器上的 exe 文件并创建一个 php 函数来切换它的可用性。我不想只是重命名、移动或删除文件,而是重定向到解释该文件暂时不可用的页面。
我知道如何在 .htaccess 中设置永久重定向,但这并不能解决我的问题,因为我想通过 php 脚本使其自动化......
有什么建议吗?提前致谢。
So basically I need a way to take an exe file on my server and make a php function to toggle it's availability. I do not want to just rename, move, or delete the file, but redirect to a page explaining the file is temporarily unavailable.
I know how to set a permanent redirect in .htaccess but this doesn't solve my problem since I'd like to make this automated via a php script....
Any suggestions? Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您将无法单独使用 PHP 来执行此操作,除非您的 Web 服务器设置为将
.exe
文件的请求处理为.php
,或者您在.htaccess。如果该文件存在,并且 .htaccess/server 设置允许直接访问文件,则 PHP 无法阻止对其的访问。You won't be able to do this with PHP alone unless your web server is set up to process requests for
.exe
files as.php
, or you add a rule in .htaccess. If the file exists, and .htaccess/server settings allow direct access to files, there's nothing PHP can do to stop access to it.老实说,最简单的方法可能是编写一个 PHP 脚本来编辑 .htaccess 文件并在 apache 中重新加载它。每当您需要启用/禁用访问时,您都可以运行该脚本。
Honestly the simplest way would probably be to write a PHP script that edits your .htaccess file and reloads it in apache. You could just run that script whenever you needed to enable/disable access.