将对PHP应用程序的请求重定向到文本文件
我想将所有到我网站的请求重定向到一个.txt文件,所以我找到了两种方法 方式1: 重定向到一个php文件,该文件将显示.txt文件内容,如下所示 .htaccess将对PHP应用程序的请求重定向到文本文件,php,.htaccess,Php,.htaccess,我想将所有到我网站的请求重定向到一个.txt文件,所以我找到了两种方法 方式1: 重定向到一个php文件,该文件将显示.txt文件内容,如下所示 .htaccess # Enable rewrite engine and route requests to framework RewriteEngine On # Some servers require you to specify the `RewriteBase` directive # In such cases, it should
# Enable rewrite engine and route requests to framework
RewriteEngine On
# Some servers require you to specify the `RewriteBase` directive
# In such cases, it should be the path (relative to the document root)
# containing this .htaccess file
#
# RewriteBase /
RewriteCond %{REQUEST_URI} \.ini$
RewriteRule \.ini$ - [R=404]
RewriteCond %{REQUEST_URI} \.html?$
RewriteRule \.html?$ - [R=404]
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php [L,QSA,E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
DirectoryIndex details.txt index.php
index.php
<?php
header('Content-type: text/plain');
header('Content-Disposition: inline; filename="details.txt"');
readfile('details.txt');
?>
所以两者都给出了相同的结果,是否还有其他我遗漏的差异。哪条路最好?我需要立即的帮助,谢谢。选择方法2'.htaccess直接重定向到.txt文件'
它将更快、更高效,因为不需要PHP解析。在第二种方法中,PHP处理程序应该解析脚本,打开文本文件并显示它。所以方法2肯定更好。方法1:您可以使用php执行任何命令,然后转到txt文件。它也将调用php引擎 方式二:直接调用txt文件。因此,它将节省您的服务器负载。但您不能执行任何命令 因为方法1将通过两个引擎,所以它将是缓慢的,但你们可以使用它,因为你们喜欢。另一方面,Way2速度更快,但是没有资源
因此,您更喜欢哪种方式取决于您的项目。好的,您是说两种方式都是相同的,但第二种方式更快,对吗?。我不担心服务器负载或其他问题,这只是一个任务,所以我想知道两者是否相同。