XAMPP .htaccess AddEncoding br brotli - apache

I install no my MacOs HighSierra fresh XAMPP (osx-7.4.6-0-vm) and start it - server runs on IP 192.168.64.2 . Then I mount /opt/lampp and click to Explore. The Finder window open and I go to directory htdocs/. Then inside htdocs I create folder assets and inside it I copy file alice.wasm (this file is compressed using brotli (br)). You can download this test (brotli compressed) file using this jsfiddle generator. Inside htdocs I create following .htaccess file
<IfModule mod_mime.c>
AddType application/wasm .wasm
AddEncoding br .wasm
AddOutputFilterByType DEFLATE application/wasm
</IfModule>
Problem
When I go to http://192.168.64.2/assets/alice.wasm browser not download file and in chrome>networks tab I see (here are more details)
(failed) net::ERR_CONTENT_DECODING_FAILED
However, when I change AddEncoding br .wasm to AddEncoding rar .wasm (or instead 'br' I use zip, or none) then browser download file (details) but the problem is that browser automatically NOT decompress file (so it save compressed file).
When I put this .htacces file and alice.wasm file to some AZURE apache-like server (but I don't have access to it configuration files) then browser download file and decompress it on the fly (details) - so this is POSSIBLE.
Question: What I should do to make XAMPP working as expected?

brotli module works only on HTTPS mod. See it here: why does not brotli work on http?. If you have ssl certificate, it will work there.

It is very strange, but when I enable port forwarding
And go to http://localhost:8080/assets/alice.wasm then Chrome download file and automatically decompress it (exactly what I want). AZURE works on HTTPS and file was downloaded properly probably because brotli compression is support only for HTTPS - however probably on Chrome localhost is 'special' and allows it too.

Related

How to configure Apache 2.4 to use 'content negotiation' in order to serve webp images?

In my HTML file there are several <img src="images/<filename>.jpeg">
The directory "images" holds these files:
<filename>.jpeg
as well as
<filename>.webp
and
<filename>.jpeg.webp
The latter two are identical webp versions of the jpeg file.
Now I want to configure Apache 2.4 on Oracle Linux 8.6 for 'content negotiation'. I am expecting that Apache returns a .webp file instead of the requested .jpeg file, if the browser supports .webp. I don't want to use the HTML <picture> tag or 'srcset' for several reasons, but leave the code untouched.
I have found several promissing configuration examples for nginx, but unfortunatly only litte on Apache:
https://gist.github.com/sergejmueller/5500879
https://stackoverflow.com/a/58857260/4335480
These two links outline 'rewrites' that are to go to the .htaccess file in the /images directory. I tried them both as '.htaccess' in the 'image' directory and it didn't work. I also put them directly in the httpd.conf and it didn't work either. And I tried these lines in the root directory's .htaccess
'AllowOverride All' is included in all section. Even the 'images' directory is explicitly listed.
In Chrome Dev Tools I verified that the request headers include 'image/webp'.
Probably not necessary: In my despair I have disabled nosniff on the Apache server and verified in the response header that it isn't set.
Whatever I try, the server only returns the jpeg file. I can verify this not only by the file name but also by the content-length field in the response header.
So what can I do to have Apache serve avif, webp and (fall back) jpeg in that order, whenever a jpeg file is requested?
Found the error myself. Note to self: don't just copy code snippets to use them. Read and understand them to find errors or identify necessary adaptions.
Vincent Orback's code is often cited for this problem, so I blindly trusted and used it: https://github.com/vincentorback/WebP-images-with-htaccess
It contains the following line:
RewriteCond %{DOCUMENT_ROOT}/$1.webp -f
The outcome is that .webp images are only searched for in the web server root directory. On my site, images are in a subdirectory called 'images'.
Trying to load an image in the browser would fail (deliver the jpeg, not the webp version):
https://<my domain>/images/<image name>.jpeg
But after altering above line to
RewriteCond %{DOCUMENT_ROOT}/images/$1.webp -f
eventually everything worked!
All the other things were unnecessary. You only need one AllowOverride All before the virtual host containers for <Directory / > and all servers and subdirectories would have .htaccess enabled, if present. For this problem, only one .htaccess in the image subdir was necessary, none in the root and no special httpd.conf entries. I turned nosniff on again. The alternativ .webp files just need the extention .webp, not .jpeg.webp

Make file downloadable without any file extension

I know we can make file downloadable using
AddType application/octect-stream .png
But if I have a file that dont have any extension (FileName) then how I will make that downloadable? or is there anyway to make all file downloadable within a directory?
You can try this directive on your site configuration (apache2):
DefaultType application/octet-stream
And this for nginx:
default_type application/octet-stream;
http://httpd.apache.org/docs/2.2/mod/core.html#defaulttype
https://nginx.org/en/docs/http/ngx_http_core_module.html
Use this in .htaccess is recommended:
<filesMatch "^([^.]+)$">
Header set Content-Disposition "attachment"
</filesMatch>
(This won't work with Chrome, it will append ".txt" to the filename, and it's a known bug)
This will prevent browser from showing the file content inline and let browser download it instead.
Executable file extension like .php (if you've installed), your browser will download the execution result(not the source code), is that what you want?

Why can't I upload .htaccess file using terminal?

I have a Amazon EC2 server running Apache, I'm trying to enable SSI using .htaccess file, I created the .htaccess file and saved it to my website files folder (not my server), and tried to upload it using scp -i /Users/jeffArries/Desktop/jeffarries.pem /Users/jeffArries/Desktop/Website_Testing_Folder/.htaccess ec2-user#ec2-54-213-219-247.us-west-2.compute.amazonaws.com:/var/www/html in Terminal, and got this error message:
"/Users/jeffArries/Desktop/Website_Testing_Folder/.htaccess: No such file or directory"
How can I upload my .htaccess file to my Apache server using Terminal?
Thanks!
Update:
Update 2:
As can be seen in the output of ls -Abl, the filename is actually .htaccess.txt.
Side note:
Enabling SSI for every .html file is a bad idea performance-wise. THe typical way is to use a special extension (like .shtml), or execute bits on the file (via XBitHack).
On Apache 2.4, the current way is to enable the INCLUDES filter instead of using AddHandler:
AddType text/html .html
AddOutputFilter INCLUDES .html
…
AddHandler server-parsed is still supported for backward compatibility.

Apache download files with specific extension

I have download directory on apache webserver. Files in this directory have specific extensions. For example *.yyy and *.zzz. But all these files are renamed .zip or .tar.gz
I've tested in different brawsers and havn't got any problems.
But some users tell that they get source of packages, not download.
I've created.htaccess
AddType application/zip .zzz
AddType application/x-gzip .yyy
But when I try to download aaa.yyy in MS Internet Explorer it try to save not aaa.yyy but aaa.gz
How to force browsers download files and not to change extensions?
<FilesMatch "\.(zzz|yyy)$">
ForceType application/octet-stream
Header set Content-Disposition attachment
</FilesMatch>
Force type tell browsers that you dont know file type. So they are not going to do any thing stupid. Second line will tell them to download this file.

how to change mime types in MAMP

I'm developing a website that has a HTML5 video. It looks like when ogg files are served with other mime types than video/ogg firefox flips. I've updated the mime.types file inside the mamp/apache/config folder and have restarted the MAMP server multiple times, but ogg files are still served with plain/text context-type.
Can someone point out what I need to do?
UPDATE
The only time I'm able to change the mime type is if I change the DefaultType text/plain to DefaultType video/ogg which is stupid.
The mime.types file is in Applications/MAMP/conf/apache
There you can alter your mime types.
Reset server after changing the file for it to take effect.
Do you have mod_mime_magic installed and enabled? Is your mime magic working correctly? When you do file -m on one of your OGG files, does it say it is a plain text file? Are the file extensions correct?
Adding mime-type is the same for all, it's just you need to understand how the types will be applied and what's the mime-type point is. In this answer I'll how I tried to add WebAssembly mime-type application/wasm in MAMP.
Here it goes:
I recently tried WebAssembly in MAMP and configured out the below mime-type that works for me.
First, we need to navigate the folder of MAMP in MacOS's Applications/MAMP/conf/apache, And then open the file mime.types in any editor.
After opening the file, add the following line anywhere in the mime.types file:
application/wasm wasm
Here is the example wasm mime type in my mime.types file:
#application/wasm
application/wasm wasm
In MAMP Pro these days you can add <VirtualHost> parameters using the gui. Here's a screenshot showing how I add MIME types for .mjs and .wasm as:
AddType application/javascript .mjs
AddType application/wasm wasm
screenshot
Don't forget to restart the server after adding.