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

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

Related

How to fix "crucial file transfer error" when opening .htaccess file in Filezilla

I have a website created with HTML, CSS, and JavaScript. I am trying to accomplish a 301 redirect (from http to a https connection) using my .htaccess file through filezilla.
When trying to View/Edit the .htaccess file, I have a "transfer error". Which doesn't let me view/download/edit the file.
when I tried finding solutions I saw people used their cPanel to edit the file instead. I have my hosting with Blacknight, and in my file manager there is no .htaccess file.
I thought there was something wrong in the way i had made the file visible in FileZilla but that wasn't the case either.
I have also tried changing the file permissions to 755 but they're reverted back to their own settings of 440 whenever I open them again.
Note: Where I can see my .htaccess file in Filezilla, is on the right hand side of the Filezilla program where remote site is, and the second box down where there are other files such as error_docs, siteapps etc.
I need the .htaccess to open so I can paste in the code below which would then do the redirect from http to https.
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NC]
The .htacces file should open when i click on it, or when I right click and then click View/Edit.
All it does now is say "transfer failed" and "critical file transfer error".
Thanks for any help :]
The solution to this was to create a new .htaccess in Blacknight Control Panel File Manager. I had already tried to show hidden files but the reason it wasn't showing was because for some reason it didn't exist in the file manager, when it did in my Filezilla.
What I had to do was:
-Open the file manager
-right click and select create new text file
-right click and select edit
-paste in the redirect code
-save file
-rename text file to .htaccess and remove the .txt extension
NOTE: Only remove the .txt extension after you have edited the file, as doing beforehand will not allow you to edit the file.
It looks like the FTP username which you are using does not have the privilege to edit the files.
You can use the cPanel --> File Manager to edit the files. You have mentioned that you are not able to see the .htaccess file when you do this. This could be because .htaccess is a hidden file and will not show on File Manager by default.
To see hidden files select File Manager. Click the top-right Settings button. Then on the Preferences window, check the option Show Hidden Files (dotfiles). Confirm the action by clicking the Save button.
After this you should be able to view and edit the .htaccess files. Please note that generally .htaccess file is in the public_html directory.

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

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

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/

deny from all in .htaccess not blocking file in the corresponding folder

I have an .htaccess file in the folder called folder and another file, called form.html in the same folder
When I try to reach the folder (by entering http://blablabla/folder/), it does block the access and I am getting an error 403 but when I enter the exact URL of the file http://blablabla/folder/form.html anf hit enter, I can access the file as easily as if I haven't put any .htaccess file.
Am I doing something wrong?
Am I missing something, should I use something like or
Sorry if the question is really basic...
.htaccess is a container for directives for your apache web server that apply to that directory and below only. What directives have you got in your .htaccess file?
The behaviour you outline above is how apache should behave with no .htaccess folder.
What is it that you are wanting to happen?

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.

Resources