.htaccess file in the root directory and it is working perfectly fine for desktop users as the files for the desktop site are in the root directory but as for my mobile site the .htaccess file does not seem to work as the mobile site files are in a sub directory named m.
So basically I'm trying to add this code in .htaccess file
<IfModule mod_expires.c>
# Enable expirations
ExpiresActive On
# Default directive
ExpiresDefault "access plus 1 month"
# My favicon
ExpiresByType image/x-icon "access plus 1 year"
# Images
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType image/jpg "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
# CSS
ExpiresByType text/css "access plus 1 month"
# Javascript
ExpiresByType application/javascript "access plus 1 year"
</IfModule>
And when I check Google page speed test its working perfectly for desktop site but as for mobile it isn't so do I have to make a separate .htaccess file for the sub directory and if yes what do I have to add in that or can I just edit the current one so that it starts working for that m sub directory?
Only a partial answer, but the Apache web server documentation says that .htaccess files apply to the directory they are in, "and to all subdirectories thereof". So you shouldn't need to create a separate .htaccess for the m sub-directory, or do anything special in your original .htaccess to make it apply to the sub-directory.
Is your web server Apache? Perhaps other web servers treat .htaccess files differently.
Related
I have an articles-blog and my articles may have a shelf-life of perhaps 1-2 weeks max. In my .htaccess I already have ExpiresByType rules (but the clutter in my MODx backend is still there and I do not understand the impact of these rules - code is below). I also have put my articles standard as indexable by the search engines.
When the shelf-life expires, I would like to permanently delete my articles. Now I do this manually and I have a whole lot of "red-crossed-out" articles titles in my back-end which makes me completely loose the overview.
My question is: What is MODx EVO best practise for my situation and is there an "automatic" way to permanently and completely (so no more red-crossed-out resource titles) remove expired articles from my MODx backend with pre-defined rules (for example, "if published time-period on the internet is 20 days then delete/remove article from MODx backend/database)"?
## Leverage Browser Caching ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access plus 1 year"
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/gif "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType text/css "access plus 1 month"
ExpiresByType application/pdf "access plus 1 month"
ExpiresByType text/x-javascript "access plus 1 month"
ExpiresByType application/x-shockwave-flash "access plus 1 month"
ExpiresByType image/x-icon "access plus 1 year"
ExpiresDefault "access plus 2 days"
</IfModule>
## Leverage Browser Caching ##
just got to know that setting expiry dates for static resources make your site go fast and jump in rankings.
My question is:
Does browser checks create date of the static resource?
If I make change to a css before 1 month, does server sends fresh copy and browser refreshes its cache?
This is the code I added to htaccess:
<IfModule mod_expires.c>
# Enable expirations
ExpiresActive On
# Default directive
ExpiresDefault "access plus 1 month"
# My favicon
ExpiresByType image/x-icon "access plus 1 year"
# Images
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType image/jpg "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
# CSS
ExpiresByType text/css "access plus 1 month"
# Javascript
ExpiresByType application/javascript "access plus 1 year"
</IfModule>
From mod_expires documentation:
The expiration date can set to be relative to either the time the source file was last modified, or to the time of the client access.
Here is the syntax:
ExpiresByType type/encoding "base[plus num type] [num type] ..."
where base is one of:
access
now (equivalent to 'access')
modification
The plus keyword is optional. num should be an integer value [acceptable to atoi()], and type is one of:
years
months
weeks
days
hours
minutes
seconds
So if you write:
ExpiresByType image/gif "access plus 1 month"
Your file will be cached as long as visitors keep requesting it without interruption for more than a month, even if you modify it.
You should then write instead:
ExpiresByType image/gif "modification plus 1 month"
Then your file will be cached for a month as long as it is not modified, otherwise the cache will be updated.
I'm having trouble with the browser-caching of SVG-files.
In my .htaccess, everything seems to be fine (at least it is rather complete) but no matter what I try, it seems as if the SVG-images aren't making their way into the browser's cache.
there's
<IfModule mod_expires.c>
ExpiresActive On
...
(various other file-types)
...
ExpiresByType image/svg+xml "access plus 1 month"
ExpiresDefault "access plus 1 month"
</IfModule>
in the .htaccess, I tried
ExpiresByType image/svg+xml A2592000
too, but nothing works. I also tried to change the mime-type to text/svg+xml. no good neither.
What could cause this failure?
Thanks
In line with the suggestion by #Ariel I checked my .conf files and I keep having the same issue, although I added
ExpiresActive on
ExpiresDefault "access plus 1 month"
ExpiresByType image/svg+xml "access plus 1 month"
ExpiresByType image/svg "access plus 1 month"
even if it is working (i assume) for svg fonts. I have no .htaccess, so everything is done in the .conf files. On that note i also have
<FilesMatch "\.(jpg|png|css|js|swf)$">
Header unset Cache-Control
</FilesMatch>
but as far as i know that wouldn't even touch the svg files. Thanks
Hi i need to add aa header expiry in my magento site.
below is the script which needs to be add expiry
https://fonts.googleapis.com/css?family=Open+Sans:300,400,700
https://platform.twitter.com/widgets.js
https://ssl.google-analytics.com/ga.js
i have a folowing code in my htacess file
<IfModule mod_expires.c>
# Enable expirations
ExpiresActive On
# Default directive
ExpiresDefault "access plus 1 month"
# My favicon
ExpiresByType image/x-icon "access plus 1 year”
# Images
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType image/jpg "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
# CSS
ExpiresByType text/css "access 1 month”
# Javascript
ExpiresByType application/javascript "access plus 1 year"
</IfModule>
Please suggest me how can i add expiry for online scripts Thanks
As of my findings on your question, It is NOT POSSIBLE and it is not recommended also. Go through this How can I add expire headers for scripts that are not on my server?
You cannot set expiry headers or any headers to files that are served from a third party. Your options are:
Copy those files locally and set your desired headers
Keep it as is and ignore any reports saying headers missing or whatever
Only in rare cases I see advantage in using #1. Otherwise, your best bet is to leave it alone.
I'm using the following line in my htaccess to set the expiration of my png files:
ExpiresByType image/png "access plus 1 month"
However, i need the png files in one exact folder to expire instantly. Is it possible to do this?
Yes, it should work if you put it in .htaccess file in that folder. Do not forget to add ExpiresActive On directive as well. For example:
Content of /images/special/.htaccess :
ExpiresActive On
ExpiresByType image/png "access plus 1 month"