Prevent PHP from parsing non-PHP files like someFile.php.txt

I just installed phpdocumentor but got weird errors. I finally discovered the problem.

Phpdocumentor creates various files, such as someFile.php.txt, which contains PHP code but is not intended for analysis. It turns out my server parses them. I also checked a file name called someFile.txt and it is not parsed.

How to prevent my PHP server from parsing files like someFile.php.txt?

My server is the PHP version 5.4.20, Apache 2.2.15 and CentOS 6.4. My file is /etc/httpd/conf.d/php.confas follows:

#
# PHP is an HTML-embedded scripting language which attempts to make it
# easy for developers to write dynamically generated webpages.
#
<IfModule prefork.c>
  LoadModule php5_module modules/libphp5.so
</IfModule>
<IfModule worker.c>
  LoadModule php5_module modules/libphp5-zts.so
</IfModule>

#
# Cause the PHP interpreter to handle files with a .php extension.
#
AddHandler php5-script .php
AddType text/html .php

#
# Add index.php to the list of files that will be served as directory
# indexes.
#
DirectoryIndex index.php

#
# Uncomment the following line to allow PHP to pretty-print .phps
# files as PHP source code:
#
#AddType application/x-httpd-php-source .phps
+4
source share
2 answers

, CentOS Apache , . , Apache. PHP /etc/httpd/conf.d/php.conf.

AddHandler php5-script .php
AddType text/html .php

#AddHandler php5-script .php
<FilesMatch \.php$>
    SetHandler application/x-httpd-php
</FilesMatch>
AddType text/html .php

Apache, .php

$ , regex regex a $ " ". , END .php (.. No .php.txt), PHP.

+7

CentOS 6.5, , php.conf.

.htaccess.

# Match anything that ends with .php.txt
<FilesMatch \.php\.txt$>
    RemoveHandler .php
    ForceType text/plain
</FilesMatch>

, - . , .php.txt . .

0

All Articles