【问题标题】:How to show php-files as plain text in Apache如何在 Apache 中将 php 文件显示为纯文本
【发布时间】:2011-05-13 07:47:38
【问题描述】:

对于我本地 Apache-Server(与 Ubuntu 一起运行)上的某个文件夹,我希望所有 *php 文件都像纯文本文件一样显示。我需要这个,因为我只想查看这些文件的源代码而不是运行它们。

在搜索时,我发现大多数人都有相反的问题 :-) 并且无法真正为我找到解决方案。

我需要在文件夹的.htacces-file 中包含什么?

谢谢!

【问题讨论】:

标签: php apache


【解决方案1】:

我的 Godaddy 设置不允许我编辑 httpd.conf 文件,并且 php_flag 命令不起作用,因为他们为我实现了 php。

我可以在我的.htaccess 文件中使用它:

SetHandler default-handler
AddType text/plain php

我把它放在上面允许我的 FTP 用户访问的目录中,这会强制该目录中的所有 PHP 文件以及所有子目录将 php 显示为纯文本。

这也适用于其他文件类型。您需要做的就是添加另一行,其中包含您希望强制以纯文本显示的任何文件扩展名。以AddType text/plain cgi 为例

【讨论】:

    【解决方案2】:

    答案:

    在 .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!)
    

    感谢布拉德!

    【讨论】:

    • 当然,解决方案总是不止一种。上述解决方案使您不必重命名数十个文件。此外,最好在 htaccess 中设置默认字符集。感谢所有在这个线程中帮助我的人!
    • 给一个将近 2 岁的答案,谢谢!我看到的大多数其他东西都错过了php_flag engine off 部分,导致问题。
    • 谢谢! (填料填料填料)
    【解决方案3】:

    查看您的 httpd.conf 文件中 .php 扩展名的 AddType,并将其更改为 text/plain,并将 php_flag engine 更改为 offvalue,就像 Sam Bisbee 所说的那样。

    但更喜欢在 httpd.conf 中进行这些更改,如果您有专用服务器,.htaccess 将毫无用处,并且会降低您的性能。

    但您也可以只更改 PHP 脚本的扩展名...

    【讨论】:

      【解决方案4】:

      我想到了两个解决方案...

      1. 将其文件扩展名更改为 .phps。例如,index.phps

      2. 在 .htaccess 文件中更改它们的内容类型。 AddType text/plain .php 使用 mod_mime 来做到这一点。更多信息http://httpd.apache.org/docs/2.2/mod/mod_mime.html#addtype

      【讨论】:

        【解决方案5】:

        关闭apache中的PHP模块? (当然,如果你不需要 php 执行)

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2020-09-30
          • 2019-08-09
          • 2012-01-31
          • 2016-04-14
          • 2014-04-01
          • 2020-05-27
          • 1970-01-01
          相关资源
          最近更新 更多