How to run php code in html file on windows server? - .htaccess

I have used .htaccess file with below code
AddType application/x-httpd-php .html .htm
it works fine in local but when I upload my files on server it is not working fine.
My all pages have html extension.

You will need to add a mapping to the PHP exe for the html extension.
IIS has a list of extensions and, based on the file extension will choose the server side processor based on this list.
If you right-click on "Web Sites" in IIS and select "Properties", you can change your ISAPI extensions.
Find the htm and html extensions and change the executable to be the same as they are for .php

Related

.htaccess is restricting access to root level pages. How do I stop this?

I have several webpages on my root directory (e.g. index.htm, home.php and home_page.php) which all are starting points for different versions of my website.
I ahve upgraded PHP version (as advised by my hosting service) from 5.3 to 5.6. This has put a .htaccess file on my site and now my PHP pages on root won't load and I get a "500 Internal Server Error" message.
The .htaccess file was created by the web hosting provider when the PHP version was updated.
The content of the .htaccess file is AddType application/x-httpd-php56 .php .php5.
If I delete the .htaccess file then my pages work OK as before but I do not know what the implications of deleteing this file are.
How do I log my exception errors?
Any help on how I can getall of my pages to be displayed, please?

Force MP3 files to download instead of opening in the browser with Quicktime

OK I have a website that serves podcasts in MP3 format. There is a .htaccess that routes requests for MP3 files to a download script, and that is as follows:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule (.*.mp3)$ download.php?file=$1
</IfModule>
The PHP download script is as follows:
$filename = (isset($_REQUEST['file']) ? $_REQUEST['file'] : '');
$filesize = #filesize($filename);
if ($filename == '' || $filesize == 0) exit(0);
header("Content-Type: audio/mpeg");
header("Content-Description: {$filename}");
header("Content-length: {$filesize}");
header("Content-Disposition: attatchment; filename={$filename}");
readfile($filename);
Everything works beautifully on PC, and in most Mac browsers. However, on Safari, Quicktime is intercepting the download. Same thing is happening on iPhone and iPad. Since the target audience is likely to be mostly Apple users, I would like the "Download" button to do just that -- download, not play in the browser with the Quicktime plugin, regardless of device. The "Stream" button can play the file in the browser, but not the "Download" button.
Doing a Right-click (or Cmd+Click) and Save File As... is not acceptable.
Is there any way to do force download across all platforms with PHP, HTTP, HTML, etc. that doesn't require the user to do anything except click the Download button?
You need to set the content-disposition HTTP header when serving the file. By setting this HTTP header it will instruct the browser to provide a prompt which lets the user save or open the file. You can find more information here:
http://support.microsoft.com/kb/260519
You can divide your streams and downloads in two separate folders in combination with the following:
"If you want to force all files in a directory to download, create a .htaccess file in that directory, then paste this in it:
## force all file types to download if they are in this directory:
ForceType application/octet-stream
Don’t stick this in your root level .htaccess file. It will cause all the files on your server to download."
You can read more about this in this conversation:
https://css-tricks.com/snippets/htaccess/force-files-to-download-not-open-in-browser/

Force a file or image to download using .htaccess

I have been trying to force images to download using PHP Headers but there have been multiple problems.
So, instead, how can I use .htaccess so that when I link to an image like:
Download
...instead of opening that file in browser, the file is actually downloaded and saved to the user's computer.
I am already using .htaccess in my project to rewrite URLs if that affects anything.
Put this into your .htaccess
<FilesMatch "\.(?i:jpg|gif|png)$">
Header set Content-Disposition attachment
</FilesMatch>
Make sure you have mod_headers installed and enabled.

.htaccess AddType plain/text

I have a page that I dynamically show my Unix scripts in another folder. I added:
AddType text/plain .sh <-- this is the only thing in .htaccess in the "unix" directory
So I could see the codes, but SOME files are still offered as a download while others go to the correct plain text display.
Here's the site live:
http://snyfarvu.farmingdale.edu/~gerbss/
Unix scripts: guess.sh, add.sh, lock.sh are the ones that are acting up
Thanks for your suggestions
It's working for me in Chrome, Firefox and Safari on Mac OS X. Did you click those links before adding the .htaccess? If so, your browser may be using the cached response which would be missing the content type header.
Try clearing your browser cache and trying again.

Serve .ICS files as binaries purely through .htaccess or apache conf

When I upload an .ICS file to the server and try to download it, it appears as text. I would like the "Save as" dialog to appear so that the user can open the file as a binary in Outlook.
What can I put into the apache conf or .htaccess rule to make the headers for ICS files work like a binary. Example: A .doc file opens like a binary.
Thanks.
You'd need to add the following line to your .htaccess file:
AddType text/calendar .ics

Resources