Where do I put the ExpiresDefault directive? I'm using CodeIgniter - apache

I'm following the High Performance Websites book and the advice is to put this:
<FilesMatch "\.(gif|jpg|js|css)$">
ExpiresDefault "access plus 10 years"
</FilesMatch>
Where do I put it anyway? I'm using COdeIgniter. And I have access to my httpd.conf file.

You actually should put it in your .htaccess file in your site root.
Additionally, You can put it in the <Directory></Directory> block in your httpd.conf but it's probably better off in your .htaccess in my opinion.

Related

Is it possible to deactivate caching Rules in htacces by IP matching?

Is it possible to deactivate caching Rules like mod_expires.c, mod_headers.c in htaccess by IP matching like < FilesMatch > or < IfModule >?
I did not find any possible solution so far. Any hints?
If you want to deactivate caching you can use the following in your .htaccess file:
ExpiresActive On
ExpiresDefault A1
Header append Cache-Control must-revalidate
Just make sure you place it at the top of your .htaccess file and clear your cache upon entering it. From that point forward it will also ask the cache to re-validate.

How to modify Content-Type in apache

We are currently having Content-Type: text/html.
We want to modify this to text/javascript or text/css.
We have tried this using rewrite rule, mod_headers and also through mod_mime, but we are unable to modify it.
Any suggestion?
Assuming you have certain text files in a directory say styles add a .htaccess file in the root directory and add the following content:
<Location /styles>
ForceType text/css
</Location>
And use the similar concept for javascript as well
I had solved this by changing the content type in application servers of content.

Does Mod Deflate automatically cache the defalted files?

I am using mod_deflate to compress javascript files. I want to know if the deflated files are cached somewhere or the files are compressed everytime they are requested for.
If they are cached, is there a way to configure the cache to improve the performance or tweak the settings ?
Thanks
NO,
you can tell the browsers to cache it on there end aswell my using
a2enmod expires
and to configure mod expire you need to do this inside this file
/etc/apache2/sites-available/default
<IfModule mod_expires.c>
<FilesMatch "\.(jpe?g|png|gif|js|css)$">
ExpiresActive On
ExpiresDefault "access plus 1 week"
</FilesMatch>
</IfModule>
test in the browser.
Now if you want to use more advanced caching they why not use varnish. If you have static content varnish will make you website fly and less burden on your apache.

RewriteRule & Header set Expires : how to

I'm using rewrite rules to create a /fr /en on my website and does folder don't exist, therefore if I try to use
<Directory /fr>
ExpiresDefault "access plus 1 day"
</Directory>
Apache complain because the folder does not exist, can't find a way to do it in the http.conf
If I use
Header set Expires "access plus 1 day"
in the .htaccess, can see the header showing
Expires: access plus 1 day
instead of the date + 1 day, if i remove it I can see
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Also if I use
ExpiresDefault "access plus 1 day"
It does not work...
Can you please tell how to get this right?
Also I believe that Safari (and only safari) keep on reloading the page every minutes because of that, is that correct or just another issue?
Thx for your help!
Directory instructions are working on real filesystem paths. So a Directory setting should looks like :
<Directory /var/www/foo/bar/fr >
(...)
</Directory>
Instead, if you prefer working with url path you must use Location directives:
<Location /fr >
(...)
</Location>
This should at least fix your inexistents directories problems (if I understand your first sentence, which is quite strange)

apache ExpiresDefault - just doesn't work

we all know that setting expire date for static files is very useful and the way i found to do so is through the ExpiresDefault property in a .htaccess file but it just doesn't work. I am using YSlow and page_speed to test the HTTP response, but it just keep on telling me that I need to set an expire date for my JS, CSS and images to speed up my application.
I tried to test ExpiresDefault "access plus 1 year" , locally ( apache server ) and on the web ( hostgator reseller account. if I have any options to make use of !?! ) but it just doesn't work. And it also doesn't return 500 error.
I feel like I am missing the main point or doing it wrong. How the whole thing should be done ?
First, identified mod_expires is compiled inside your apache.
Try
PATH_TO_YOUR/httpd -M | sort /* <-- look for expires_module*/
And your apache configuration should be like
ExpiresActive on
ExpiresDefault "access plus 1 year"
And always restart apache after configuration changed