对于我本地运行的Ubuntu Apache服务器上的某个文件夹,我希望所有*php文件都显示为纯文本文件。我需要这样做是因为我只想查看这些文件的源代码而不运行它们。
在搜索过程中,我发现大多数人都有相反的问题:-) ,并且找不到适合我的解决方案。
我需要在我的文件夹的.htaccess文件中包含什么内容?
谢谢!
在搜索过程中,我发现大多数人都有相反的问题:-) ,并且找不到适合我的解决方案。
我需要在我的文件夹的.htaccess文件中包含什么内容?
谢谢!
答案:
在 .htaccess 文件中输入以下内容
php_flag engine off
#This will prevent apache from executing *.php-files
AddType text/plain php
#this wil display php-files in browser (if not, browser will want to download file!)
感谢Brad!php_flag engine off
这一部分,导致出现了问题。 - TarkaSetHandler default-handler
AddType text/plain php
AddType text/plain cgi
。AddType
后面是否跟着.php
扩展名,将其更改为text/plain
,并将php_flag engine
更改为关闭状态value
,就像Sam Bisbee所说的那样。最好在httpd.conf中进行这些更改,如果您有专用服务器,则.htaccess是无用的,并会降低性能。但您也可以只更改PHP脚本的扩展名...我脑海中有两个解决方案...
将文件名扩展名更改为.phps,例如:index.phps
。
在.htaccess文件中更改它们的Content-type。使用AddType text/plain .php
通过mod_mime实现此操作。更多信息请参见http://httpd.apache.org/docs/2.2/mod/mod_mime.html#addtype