我想将我的网站的所有请求重定向到.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 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}]
的index.php
<?php
header('Content-type: text/plain');
header('Content-Disposition: inline; filename="details.txt"');
readfile('details.txt');
?>
方式2:
使用.htaccess直接重定向到.txt文件
的.htaccess
DirectoryIndex details.txt index.php
所以两个都给我相同的结果,我还有其他任何不同之处。哪种方式最好?我需要立即帮助,谢谢。
答案 0 :(得分:2)
方式1:您可以使用php执行任何命令,然后转到txt文件。它也会调用php引擎。
方式2:它将直接调用txt文件。因此它将节省您的服务器负载。但是你不能执行任何命令。
由于Way 1将通过两个引擎,所以它会很慢,但你可以随意使用它。另一方面,Way 2将更快但无源。
您更喜欢哪种方式取决于您的项目。
答案 1 :(得分:1)
转到Way2&#39; .htaccess直接重定向到.txt文件&#39;
它将更快更有效,因为不需要PHP解析。在第二种方法中,PHP处理程序应该解析脚本,打开文本文件并显示它。所以Way2肯定更好。