I added next lines in .htaccess, which I found here How to specify vary accept encoding header in htaccess
<IfModule mod_headers.c>
<FilesMatch "\.(js|css|xml|gz)$">
Header append Vary Accept-Encoding
</FilesMatch>
</IfModule>
but it isn't works, also I checked phpinfo (Loaded Modules: mod_headers...).
I use Page Speed plugin and I can't see this header in my css file.
Why it isn't works?
Maybe you want use this:
<IfModule mod_headers.c>
<FilesMatch "\.(js|css|xml|gz)$">
Header append Vary: Accept-Encoding
</FilesMatch>
</IfModule>
with semicolon
Add this one in .htaccess file ,it will work
<IfModule mod_headers.c>
<FilesMatch ".(js|css|xml|gz|html)$">
Header append Vary: Accept-Encoding
</FilesMatch>
</IfModule>
If the other examples doesn't work, try this:
<IfModule mod_headers.c>
Header set Vary "Accept-Encoding"
</IfModule>
Related
I've followed https://developer.mozilla.org/en-US/docs/Learn/Server-side/Apache_Configuration_htaccess#cross-origin_images and these stackoverflow answers Access-Control-Allow-Origin Multiple Origin Domains?
To try and get this to work nicely. But it's throwing a mismatch on some origins and some, it works as expected.
htaccess update
<IfModule mod_rewrite.c>
<IfModule mod_setenvif.c>
<IfModule mod_headers.c>
# Allowing fonts for specific origins on mtn domains and local testing
<FilesMatch "\.(ttf|otf|eot|woff|woff2)$">
SetEnvIf Origin "^http(s)?://(.+\.)?(fiddle\.jshell\.net|lab4\.onlinecms\.mtn\.co\.za|mtndecoupled\.lndo\.site:444|localhost:4200)$" AccessControlAllowOrigin=$0
Header add Access-Control-Allow-Origin %{AccessControlAllowOrigin}e env=AccessControlAllowOrigin
Header set Access-Control-Allow-Credentials true
</FilesMatch>
</IfModule>
</IfModule>
</IfModule>
Screenshots of CORS error:
mtndecoupled.lndo.site:444 https://share.getcloudapp.com/geuA8QxY
lab4.onlinecms.mtn.co.za https://share.getcloudapp.com/Wnu0z94G
localhost:4200 https://share.getcloudapp.com/P8uGvzgx
jsfiddle https://jsfiddle.net/ft92z8c3/1
Edit
Error message in browser console:
CORS header 'Access-Control-Allow-Origin' does not match 'mtndecoupled.lndo.site:444'
Not sure if it's the module check or the set env regex. I'm hoping someone can give more information for this and how I can resolve it.
Appreciate any feedback.
Ok managed to fix this. Hope this might help someone else having this issue.
We are using Varnish cache and realised it was caching the first domain hit. So we updated the htaccess as:
<IfModule mod_rewrite.c>
<IfModule mod_setenvif.c>
<IfModule mod_headers.c>
# Disable caching
Header set Cache-Control "no-cache, no-store, must-revalidate"
Header set Pragma "no-cache"
Header set Expires 0
# Allowing fonts for specific origins on mtn domains and local testing
<FilesMatch "\.(ttf|otf|eot|woff|woff2)$">
<IfModule mod_expires.c>
ExpiresActive Off
</IfModule>
<IfModule mod_headers.c>
FileETag None
Header unset ETag
Header unset Pragma
Header unset Cache-Control
Header unset Last-Modified
Header set Pragma "no-cache"
Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
Header set Expires "Thu, 1 Jan 1970 00:00:00 GMT"
SetEnvIf Origin "^http(s)?://(.+\.)?(fiddle\.jshell\.net|lab4\.onlinecms\.mtn\.co\.za|mtndecoupled\.lndo\.site:444|localhost:4200)$" AccessControlAllowOrigin=$0
Header add Access-Control-Allow-Origin %{AccessControlAllowOrigin}e env=AccessControlAllowOrigin
Header set Access-Control-Allow-Credentials true
</IfModule>
</FilesMatch>
</IfModule>
</IfModule>
</IfModule>
loading a webpage i get this error:
A 'cache-control' header is missing or empty.
for favicon.ico resource.
My .htaccess is so configured:
<IfModule mod_headers.c>
Header always set X-Content-Type-Options nosniff
Header unset Expires
Header unset Pragma
Header unset X-Powered-By
<FilesMatch "\.(php)$">
Header set Cache-Control "no-cache"
</FilesMatch>
<Files "favicon.ico">
Header set Cache-Control max-age=31536000
</Files>
</IfModule>
How i can fix it?
In my .htaccess did I manage to activate a pop-up box with save-as and open options for a file download, those files being images, jpg, jpeg, png etc. This works perfectly.
Here the code:
<IfModule mod_headers.c>
<FilesMatch "\.jpg$">
Header append Content-Disposition "attachment;"
</FilesMatch>
<FilesMatch "\.jpeg$">
Header append Content-Disposition "attachment;"
</FilesMatch>
<FilesMatch "\.png$">
Header append Content-Disposition "attachment;"
</FilesMatch>
<FilesMatch "\.ogv$">
Header append Content-Disposition "attachment;"
</FilesMatch>
<FilesMatch "\.mov$">
Header append Content-Disposition "attachment;"
</FilesMatch>
<FilesMatch "\.avi$">
Header append Content-Disposition "attachment;"
</FilesMatch>
<FilesMatch "\.mp4$">
Header append Content-Disposition "attachment;"
</FilesMatch>
</IfModule>
Now I want to have the same feature for VIDEO files (ogv, avi, mp4, etc.), and I added the code the same way, but it does not work for video files, how to make this solution work?
You can use AddType to force the downloads:
AddType application/octet-stream .ogv
AddType application/octet-stream .avi
AddType application/octet-stream .mp4
Alternatively, you can use this method, and incorporate the other file types you've alrady done:
<FilesMatch "\.(jpe?g|png|ogv|mov|avi|mp4)$" >
ForceType application/octet-stream
Header add Content-Disposition "attachment"
</FilesMatch>
This is also an option you can try:
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule \.(jpe?g|png|ogv|mov|avi|mp4)$ - [T=application/octet-stream]
Regarding Firefox: It appears that FF requires the filename to be set. This is the best way I can think of doing it - and it appears to work perfectly:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^(.+).(jpe?g|png|ogv|mov|avi|mp4)$ - [env=filename:$1.$2]
<FilesMatch "\.(jpe?g|png|ogv|mov|avi|mp4)$" >
ForceType application/octet-stream
Header add Content-Disposition "attachment; filename=%{filename}e"
</FilesMatch>
Here, we're checking to see if the request is for an existing file, and if the file ends with a certain extension. If so, set an environment variable called filename, and pass it to Header add. Quite magical, really. Firefox is quite strict with a few other things too - so this is good to know.
In my social engine web site , it always shows mydomain.com/index.php instead of mydomain.com
For example when we access the member page it shows mydomain.com/index.php/member , but actually I would like to get it as mydomain.com/members
Please see my htacess code under /public folder here
<FilesMatch "\.(avi|flv|mov|wmv|wma|mp3|mp4|m4a|mkv|swf|pdf|doc|ppt|ico|jpg|jpeg|png|gif|js|css)$">
<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault A29030400
<IfModule mod_headers.c>
Header append Cache-Control "public"
</IfModule>
</IfModule>
<IfModule !mod_expires.c>
<IfModule mod_headers.c>
Header set Expires "Sun, 1 Jan 2012 00:00:00 GMT"
Header append Cache-Control "max-age=172800, public"
</IfModule>
</IfModule>
</FilesMatch>
How can I solve this ?
Thanks in advance
Sunil
Why your .htaccess is inside /public folder? It should be inside a root socialengine folder, where .htaccess enables rewrite mode...
In my .htaccess I have this code:
<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf|txt|html|x-html|php|css|xml|js|woff|ttf|svg|eot)(\.gz)?$">
ExpiresActive On
Header set Expires "Sun, 27 May 2012 00:00:00 GMT"
Header unset ETag
FileETag None
</FilesMatch>
It seems to work perfectly on some servers, but not on one of my websites. I get a 500 Internal Server Error.
Is there anything wrong in the config, or do I have to contact my host?
Ensure that you have these Apache modules enabled and loaded:
ExpiresActive -- mod_expires
Header -- mod_headers
Try this instead (it will only use directives if corresponding module is present):
<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf|txt|html|x-html|php|css|xml|js|woff|ttf|svg|eot)(\.gz)?$">
<IfModule mod_expires.c>
ExpiresActive On
</IfModule>
<IfModule mod_headers.c>
Header set Expires "Sun, 27 May 2012 00:00:00 GMT"
Header unset ETag
</IfModule>
FileETag None
</FilesMatch>