Re: Adding a single php file to .htaccess.

From: Date: Sun, 24 Aug 2008 20:07:45 +0000
Subject: Re: Adding a single php file to .htaccess.
References: 1 2 3 4 5 6 7 8  Groups: php.general 
Request: Send a blank email to php-general+get-278603@lists.php.net to get a copy of this message
Stut schreef:
On 24 Aug 2008, at 16:30, Dotan Cohen wrote:
2008/8/24 Stut <stuttle@gmail.com>:
I'm confused. A #! line does not harm the portability of a PHP script in any way whatsoever, and if you use the env version rather than an absolute path then it should work out of the box on 99% of Linux servers and will also work everywhere else because that line will be ignored by the PHP interpreter. In what way do you think it harms the portability of the PHP file itself?
Because I have a few other files that do not have the shebang line that I will likely need to put on that server in the future, and I did not want to have to remember to add the shebang line for each one. However, the flaw in my thinking is that I would in any case have to add the line to .htaccess for each file, which means SSHing in instead of FTPing. So the shebang line is in fact best! In any case, I would still like to know what line to add to .htaccess to have it parse a specific file as php. But it is no longer critical for this project because I will use the shebang line.
It depends what version of Apache you're using, but it would be a Files section something like this (Apache 2 filter in this example, but untested - I've never needed to do this)... <Files firstfile.html>
    SetOutputFilter PHP
    SetInputFilter PHP
</Files>
there is also ForceType directive that can be used in a Files directive to achieve pretty much the same thing ... an old trick I've used to force certain .css files through php whilst keeping the extension (which some browsers rely on [nice :-(], regardless of headers that you send to tell the browser it's CSS!!) also FilesMatch can be used with a regexp to match more than one file succintly ... and IIRC Files allows multiple file name arguments in the opening 'tag'
Repeat for each file. For other versions of Apache check the installation section of the PHP manual. -Stut


« previous php.general (#278603) next »