Can I have all .html pages parsed as PHP?
By default, files ending in .php, .php3, .php4 and .phtml will be parsed as PHP and you do not need to do anything to make this happen.
If you want all .html files parsed as PHP, just add the following line to an .htaccess file in the same directory or any directory above the one in which you want this behavior:
AddHandler cgi-script .html
To also have all .htm files parsed as PHP, add .htm to the end of the above line. Nothing else is required if you want .htm or .html files to be parsed as PHP.
If you want any other filetype other than .htm or .html to be parsed as PHP, such as .wow then you will have to do as above:
AddHandler cgi-script .wow
plus you will have to make all your .wow PHP files world executable (
chmod -R 755 *.wow) and put the following on the first line of every .wow file before any opening php tags:
#!/usr/bin/php
Those 3 steps (AddHandler, chmod, and #!/usr/bin/php) are necessary when you want filetypes other than .htm and .html to be executed as PHP.
User-Contributed Notes
 |
user -at- example.com 17-Sep-2002 10:46 |
#!/usr/bin/php doesn't seem to work but #!/usr/local/bin/php does.
|
|
user -at- example.com 17-Sep-2002 13:26 |
#!/usr/bin/php seems to only need to be used on the very first open php
tag
|
|
| 16-Oct-2002 10:30 |
If you need an alternative to ForceType to parse extensionless files as
php AND you are trying to use $PATH_INFO to carry query string variables
(in order to avoid URLs with query strings), like:
http://www.yourdomain.com/extensionlessfile/varname/varvalue
where "extensionlessfile" is the filename of the php script that does
the parsing of "varname", then you need to cd into the same directory as
extensionlessfile and make a symlink from "extensionlessfile" to a file
with a .php extension like this:
ln -s extensionlessfile extensionlessfile.php
Then use mod_rewrite to pass all requests for the above URL invisibly to
the .php script by putting these rewrite rules in an .htaccess file in
the same directory or above this directory:
RewriteEngine on
RewriteCond %{REQUEST_URI} !extensionlessfile\.php
RewriteRule ^extensionlessfile(.*)$ /extensionlessfile.php$1
|
|
| 07-Mar-2004 03:41 |
If you're trying to run a weird file extension that requires you to have
#!/usr/local/bin/php
at the top of each file, you can do that real quick to your entire file
tree by doing this from a shell prompt:
cd /htdocs
cp -a www www-old
cd www
find . -type f -name \*.weirdextension -exec perl -pi -e 'print
"#!/usr/local/bin/php\n" if($. == 1); close ARGV if eof' {} \;
That was 4 commands, 1 on each line hitting ENTER in between. The last
one is a long one and should be all on 1 line even though it wraps
around and looks like multiple lines in this note.
That will make a backup of your existing files first, and then find
every file under your tree that is named like *.weirdextension and it
will prepend the appropriate hash-bang line at the top of all those
files.
|
|
mbevan at marginsoftware dot com 25-Apr-2004 14:35 |
Using mod_rewrite is rarely useful, I find. This is mainly due to the
fact that all requests need to go through Apache's file find functions
twice. Once as 'testpage', which triggers the rewrite, and once as
'testpage.php', which is passed through the rewrite again, but does not
trigger it. This is hardly efficient.
As for which #!/.../php lines work - it's entirely dependant on your
installation of PHP. Some PHP installations will install the php
executable in /usr/local/bin, some in /usr/bin, and some in more exotic
locations (like /opt/php-version/bin) and some installations do not have
a command-line version of PHP at all!
Having the first line of a file starting with #! and a path to an
executable started long ago with shell scripts, and has continued to
this day as a useful way of telling the system which program to dump the
file into. Other common examples are #!/bin/bash, #!/bin/sh,
#!/usr/bin/perl, #!/usr/bin/python, etc. If you use a first line of
#!/bin/cat you will get out what you put in. Using programs like 'sed'
you can create interesting (and blindingly fast) search-and-replace
statements, and more.
An even better example would be to AddHandler cgi-script .xml and
specify "#!/usr/bin/xsltproc -" as the first line. You can have a
properly formatted XML document automatically converted to HTML this
way. (Though I don't reccomend it, as this would be horribly slow. Try
a combination of XML, XSLT, and PHP for cacheing.)
|
|
| 26-Apr-2004 16:30 |
The "ForceType" directive is unsupported here. In the future, Apache
will not be compiled with PHP inside it as a module. At that point php
will not be part of the httpd and so "x-httpd-php" will be a
nonfunctional directive and will break any site that relies on it. That
is why the mod-rewrite alternative to Forcetypes is suggested above.
|
|
| 16-Dec-2004 13:15 |
If you're trying to get rid of a ForceType directive for an
extensionless file, and you've got a number of extensionless files in
the same directory that all need to be parsed as PHP, then make the .php
symlinks as per the above, but then use this rewrite rule:
RewriteEngine on
RewriteCond %{REQUEST_URI} /(file1|file2|file3|file4)$
RewriteRule .* %1.php
If the extensionless files are not at the DocumentRoot, then you'll need
a RewriteBase directive. For example, if the extensionless files were
under /htdocs/www/example (where /htdocs/www is the DocumentRoot), then
you'd add this to the rewrite ruleset:
RewriteBase /example
|
|
anonymous -at- example.com 25-Aug-2007 02:23 |
AddType application/x-httpd-php .html
is another way to do it.
|
|
 |
Related Questions:
How do I set PHP include_path?
What PHP modules are available and how do I load them?
How do I change timezone for PHP?
How do I do html form file uploads?
Can I run a PHP script on cron?
Why does a PHP function give an error that it is undefined?
Why does PHP HTTP authentication not work?
Can you change session cookie timeout in php.ini for me?
Why does my PHP script throw an Internal Server Error 500?
I can't upload a file larger than 8MB through a PHP script
What version of PHP are you running and can I see a phpinfo()?
Do you have a quick form mail script?
Do you offer PHP5 with MySQLi?
Can I use a PHP extension like PDFlib that I have personally purchased a license to use?
What's the difference between running PHP as a cgi or as a module in safe mode?
Do you provide PEAR?
The PHP curl module doesn't work.
Where is the php_error_log?
My PHP session is lost whenever I go to a secure URL using the shared SSL certificate.
Where can I download free PHP scripts?
Do I need to set any 777 permissions in order for my PHP scripts to create files and directories?
How do I get different character sets within my PHP page to display correctly?
Can I use Smarty Templates?
The PDFlib extension gives a UPR description error.
How do I execute my .php files as PHP 5?
How do I use the url_rewriter.tags setting for PHP?
Why does flush() not flush the data to my browser?
Why does PHPLIB sessions give me a MySQL Database error?
The pfpro pfpro_process() function keeps giving me Error 31
Will my Zend Encoded files work?
Will IonCube encoded files work?
What is CAPTCHA? How can I use it?
I need the virtual() function and it is not available.
Why does getallheaders() say undefined function?
Can I talk over SSL when opening an IMAP connection with the PHP imap_open() function?
My PHP script needs a newer version of Zend Optimizer. What do I do?
How can one PHP file transparently handle all search-engine friendly URLs?
How do I put PHP sessions into a database instead of the default files-based method?
Browse Categories:Getting Started, FTP, Telnet/SSH, Moving Domains, E-mail, Traffic Reports, Mailing Lists, Apache, PHP, CGI, Other Server-Side Scripting, MySQL Database, Imaging Libraries, Other Software, Billing & Terms, Control Panel, E-commerce, Pre-Sales |