[英]Can I set up a PHP file to act as a handler for a file extension?
Lets say I have a file with a .quote
extension. 可以说我有一个扩展名为.quote
的文件。 I'd like the web server to send the contents of this file through a simple PHP script before sending it to the browser. 我希望Web服务器先通过简单的PHP脚本发送此文件的内容,然后再将其发送到浏览器。
For example: 例如:
This is a quote 这是一个报价
Would be transformed to 将转化为
"This is a quote" “这是一个报价”
It looks as though I need to put something in my .htaccess
along the lines of 似乎我需要按照以下方式在.htaccess
放入一些内容:
AddHandler x-quote .quote
Action x-quote /cgi/quote.cgi
And then my script would be something like 然后我的脚本会像
#!usr/local/php5
<?php
header("Content-type: text/plain");
#I don't know how to do this step...
echo '"'.$CONTENTS_OF_THE_FILE.'"';
?>
However, now I just get an error 404 when I look at the .quote
file on the server. 但是,现在当我查看服务器上的.quote
文件时,只会出现错误404。 I can think of a few things that might be causing this: 我可以想到可能导致此问题的一些原因:
I do not have SSH access to the server in question. 我没有对有问题的服务器的SSH访问。
Why not just run it through a normal PHP file rather than CGI and use mod_rewrite? 为什么不通过普通的PHP文件而不是CGI运行它并使用mod_rewrite? Your .htaccess would look like 您的.htaccess看起来像
RewriteRule ^(.+?).quote$ quote.php?f=$1
Your PHP: 您的PHP:
<?php
header("Content-type: text/plain");
$quote = file_get_contents($_GET['f']);
echo '"'.$quote.'"';
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.