I'd like to accept other type of files that contains PHP code. For example, it would be nice to read an .aspx file by PHP as if it were .php.
Add this to your .htaccess file in Apache to make html parse as PHP:
AddType application/x-httpd-php .html
You can extrapolate what you need to do from there. :-)
Use this htaccess rule:
AddType application/x-httpd-php .php .aspx
Yes, this is done in your Apache configuration. You tell apache what kind of files you want it to send to the PHP engine. You can do this configuration the same way you do other apache configuration - in the main config file, per site, or in .htaccess files.
Related
for a certain folder on my local Apache-Server (running with Ubuntu) I'd like that all *php-files will be displayed as if they were plain text-files. I need this since I only want to see the source code of these files and NOT run them.
While searching, I found that most people have the opposite problem :-) and couldn't really find a solution for me.
What would I need to include in the .htacces-file of my folder?
THANKS!
THE ANSWER:
in .htaccess-file type
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!)
Thanks to Brad!
My Godaddy setup wont allow me to edit the httpd.conf files, and the php_flag command doesn't work due to how they've implemented php for me.
I was able to use this in my .htaccess file:
SetHandler default-handler
AddType text/plain php
I put this in the directory above where my FTP user is allowed to access, which forces all PHP files in that directory, as well as all sub-directories to show php as plain text.
This will work for other file types as well. All you need to do is add another line with whatever extension of file you want to be forced to display in plain text. AddType text/plain cgi for example
Look at your httpd.conf file for the AddType of .php extension, and change it fortext/plain, and php_flag engine to the offvalue just as sait by Sam Bisbee.
But prefer do these change in the httpd.conf, the .htaccess are useless if you have a dedicated server, and lowing your perfs.
But you can also just change the extensions of your PHP scripts...
Two solutions off the top of my head...
Change their file name extensions to .phps. Ex., index.phps.
Change the Content-type for them in the .htaccess file. AddType text/plain .php uses mod_mime to do this. More info at http://httpd.apache.org/docs/2.2/mod/mod_mime.html#addtype
Turn off the the PHP module in apache? (if you won't be needing php execution, of course)
Just wanted to know what code I have to put in my .htaccess file so my html pages read php that im going to put in there, (just a contact form), I did find it once but can't remember, sorry and thanks.
You have to convert your html files to php
put this line in your .htaccess if you're using apache2
AddType application/x-httpd-php .html .htm
but make sure that your .htaccess file is in the root directory of the website
If you want PHP in HTML files to be interpreted just add this line to your .htaccess file:
AddType application/x-httpd-php .html .htm
HTML Pages don't read your PHP. Instead Apache is reading your file and executes it with a PHP interpreter if some PHP is in there.
Just in case you have a debian server with apache2 you can apt-get install php5. But there is a lot more work to do, for example FCGI and so on.
As we know, it is easy to get Apache to handle .html pages as PHP pages by adding the following line to http.conf:
AddHandler application/x-httpd-php .php .html
How can this be done in OpenShift?
How can I edit http.conf in OpenShift?
Or is there another way?
Have you tried using a .htaccess file? Try the answer from this stackoverflow question, but use php instead of perl/python: perl on php application on openshift
It's easy, just add the following line to your .htaccess in any folders that it is required: AddHandler application/x-httpd-php .php .html
I want to upload a PHP file to a server under a PNG extension, while still being able to view it in my browser as a PHP file. How can I do that? Thanks.
Use the following in your .htaccess file in the directories where your files are:
<FilesMatch "\.png$">
SetHandler application/x-httpd-php
</FilesMAtch>
http://httpd.apache.org/docs/2.2/mod/mod_mime.html
http://bytes.com/topic/php/answers/745293-force-apache-parse-html-files-php
Note that ALL files with .png will be handled by PHP with this.
You can add AddType application/x-httpd-php .png to an .htaccess file (assuming your host allows you to use .htaccess files), and Apache will send those file off to be parsed by PHP.
Why not use URL Rewriting for this?
You cannot. PHP is server-side code and is not rendered in the browser.
I have a quick question about changing the file types PHP parses. This website gave this line:
AddType application/x-httpd-php .php
But I'm not clear what file this goes into. Any help would be appreciated - thanks!
That line goes into a file called .htaccess, that changes the Apache server configuration for the folder it is on, and all its subfolders (Unless otherwise specified)
Your server should parse php files with the .php file extension by default though. You could use that to add custom file formats for example.
To parse .mp4 files, like you said in the comments, add to your .htaccess:
AddType application/x-httpd-php .mp4
You need to write that in your .htaccess file.
That makes Apache parse .php files through the PHP interpreter.
You can either add that to your .htaccess or httpd.conf file, depending on what you have access to.