I'm not sure this is possible, but I'd like to write a rewrite rule (and any other instruction if needed) in a .htaccess file so that, for every url in that folder, any url ending in .txt is rewritten to the same name ending in .php, but in addition, in this case the php file is NOT executed but its content (source code) is served instead.
That is, being "myfolder" the folder where I want this to apply:
http://www.mydomain.com/myfolder/somescript.php => would run somescript.php as usual http://www.mydomain.com/myfolder/somescript.txt => would return the source code of somescript.php without running it
There are two ways of accomplishing this.
Symlink each
.php
file to.txt
and add a directive in Apache like:within a
<VirtualHost>
,<Location>
or<Directory>
block.Putting it inside a
<Location
> is probably best so that .txt files aren't globally associated as being PHP source.Use a rewrite rule such as:
(source: http://httpd.apache.org/docs/2.2/rewrite/flags.html#flag_h - modified slightly)
With this option, ensure that no other files will exist in the directory called
.txt
otherwise they will be sent with a Content-type of x-httpd-php-source. You may need to adjust the regex if this is the case.