Turn of Htaccess Caching in Admin - apache

I have a Laravel development. I want the htaccess file to work on the front end, but I don't want it to cache anything in the admin. All admin pages are in the directory /home/ - I want to make the code shown below NOT apply to anything in this folder.
How can I achieve this?
In my htaccess file is the following code:
<ifModule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus 5 seconds"
ExpiresByType image/x-icon "access plus 2592000 seconds"
ExpiresByType image/jpeg "access plus 2592000 seconds"
ExpiresByType image/png "access plus 2592000 seconds"
ExpiresByType image/gif "access plus 2592000 seconds"
ExpiresByType application/x-shockwave-flash "access plus 2592000 seconds"
ExpiresByType text/css "access plus 604800 seconds"
ExpiresByType text/javascript "access plus 216000 seconds"
ExpiresByType application/javascript "access plus 216000 seconds"
ExpiresByType application/x-javascript "access plus 216000 seconds"
ExpiresByType text/html "access plus 600 seconds"
ExpiresByType application/xhtml+xml "access plus 600 seconds"
</ifModule>
<IfModule mod_headers.c>
<filesMatch "\.(ico|jpe?g|png|gif|swf)$">
Header set Cache-Control "public"
</filesMatch>
<filesMatch "\.(css)$">
Header set Cache-Control "public"
</filesMatch>
<filesMatch "\.(js)$">
Header set Cache-Control "private"
</filesMatch>
<filesMatch "\.(x?html?|php)$">
Header set Cache-Control "private, must-revalidate"
</filesMatch>
Header set X-XSS-Protection "1; mode=block"
Header always append X-Frame-Options SAMEORIGIN
Header set X-Content-Type-Options nosniff
</IfModule>
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript
SetOutputFilter DEFLATE
SetEnvIfNoCase Request_URI "\.(?:gif|jpe?g|png)$" no-gzip
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
Note: There is no actual admin folder called "home" so i can't make another htaccess file. When i do make a "home" folder it creates a strange error and loop because all admin folders in laravel are dynamic and controlled by the routes file.

You can create a new .htaccess file in you /home/ directory where is located pages for administration use only with the simple content:
<ifModule mod_expires.c>
ExpiresActive Off
</ifModule>
And you need to check if in Apache or Nginx configuration of virtual host is allowed to Override All

Related

PHP 7.0.22 : mod_deflate enabled & .htaccess in place but doesn't seem to do anything

I have a website setup using Plesk within PHP 7.0.22 being run as FPM application served by Apache.
So far everything has been running great however when I attempted to enable compression within .htaccess as I normally would nothing appears to be compressed.
#SERVER COMPRESSION
<IfModule mod_deflate.c>
SetOutputFilter DEFLATE
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE image/x-icon
AddOutputFilterByType DEFLATE image/svg+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/x-font
AddOutputFilterByType DEFLATE application/x-font-truetype
AddOutputFilterByType DEFLATE application/x-font-ttf
AddOutputFilterByType DEFLATE application/x-font-otf
AddOutputFilterByType DEFLATE application/x-font-opentype
AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
AddOutputFilterByType DEFLATE font/ttf
AddOutputFilterByType DEFLATE font/otf
AddOutputFilterByType DEFLATE font/opentype
# For Olders Browsers Which Can't Handle Compression
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
</IfModule>
## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType image/svg "access 1 year"
ExpiresByType text/css "access 1 month"
ExpiresByType text/html "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 1 month"
</IfModule>
# 1 day for most static assets
<ifModule mod_headers.c>
Header set Connection keep-alive
</ifModule>
I contacted the server admin to enquire incase the mod_deflate module wasn't enabled but have been assured that it is, having been given screen shoots as proof.
Kind of stumped at this point any ideas where I should go from here?
This may be a silly question and I'm not sure which version of Plesk you are using, but:
Do you have a "Apache & nginx Settings" icon in Plesk?
If so, is "Serve static files directly by nginx" disabled? If not, try disabling it and see if it makes a difference.*
You can also try playing with the other proxy checkbox options.
*(If mod_pagespeed is enabled, it would be better to leave it enabled but only have "htm html" in it, else they will appear blank.)
Turns out it was because the hosting environment was setup using a mish mash of both Apache & Nginx.
The server admin updated the Nginx directives to enable compression.

Prevent the browser from caching PHP requests

I'm having an issue with PHP file caching on my website.
Here's what my .htaccess file looks like right now:
Header add Access-Control-Allow-Origin "*"
Header add Access-Control-Allow-Headers "origin, x-requested-with, content-type"
Header add Access-Control-Allow-Methods "GET, POST"
# PHP Errors
php_flag display_startup_errors on
php_flag display_errors on
php_flag html_errors on
php_flag log_errors on
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE image/x-icon
AddOutputFilterByType DEFLATE image/svg+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/x-font
AddOutputFilterByType DEFLATE application/x-font-truetype
AddOutputFilterByType DEFLATE application/x-font-ttf
AddOutputFilterByType DEFLATE application/x-font-otf
AddOutputFilterByType DEFLATE application/x-font-opentype
AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
AddOutputFilterByType DEFLATE font/ttf
AddOutputFilterByType DEFLATE font/otf
AddOutputFilterByType DEFLATE font/opentype
# For Olders Browsers Which Can't Handle Compression
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
</IfModule>
<IfModule mod_expires.c>
# Enable expirations
ExpiresActive On
# Default directive
ExpiresDefault "access plus 1 month"
ExpiresByType image/x-icon "access plus 3 month"
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"
ExpiresByType image/svg+xml "access plus 1 month"
ExpiresByType text/css "access plus 1 week"
ExpiresByType application/javascript "access plus 1 week"
ExpiresByType text/javascript "access plus 1 week"
</IfModule>
<filesMatch "\.php">
FileETag None
Header unset ETag
Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
Header set Pragma "no-cache"
Header set Expires "Wed, 11 Jan 1984 05:00:00 GMT"
</filesMatch>
I have a php script (A) [that looks something like this http://www.mywebsite.com/index.php?id=13&tc=xyhskfuw&ml=786w] which posts data [via curl] to another script (B), and then (irrespective of the result) redirects to a html page (C). The script (B) does a database operation.
The problem I'm having is that script (A) only seems to run once, even after repeated posts in the browser's address bar. It redirects correctly every time, but script (B) (which is supposed to receive data from script (A)) doesn't run more than once.
I'm testing this in the Firefox browser (with developer tools open), and I ran the script with the Network tab open. In the list of HTTP requests, I see that the .php script has a Status Code of 302, and under the Transfer header it says cached.
On further inspection by looking at the headers, here's what I see:
Access-Control-Allow-Headers: origin, x-requested-with, content-type
Access-Control-Allow-Methods: GET, POST
Access-Control-Allow-Origin: *
Cache-Control: max-age=2592000
Content-Length: 0
Content-Type: text/html; charset=UTF-8
Date: Fri, 19 Aug 2016 19:21:39 GMT
Expires: Sun, 18 Sep 2016 19:21:39 GMT
I'd like to prevent this from happening. What can I do to disable the browser from caching PHP requests?
I managed to figure this out after carefully poring over the .htaccess file.
I noticed this entry: ExpiresDefault "access plus 1 month". It turns out the default caching lifecycle is exactly 1 month, which would explain max-age=2592000; being that 2592000 seconds make up 30 days. I had no idea it applied to php though.
Anyway, I updated said entry to this: ExpiresDefault "access plus 0 seconds".
It seems to be working fine now.

correct htaccess caching parameters

I have been reading up on the subject of htaccess caching to help increase the speed of my website. I put together the following based on the information from different website sources as I want to improve the speed of my cms.
Can someone tell me if this is the proper way to use the parameters?
### caching rules
<IfModule mod_mime.c>
AddType application/x-javascript .js
AddType text/css .css
</IfModule>
<IfModule mod_deflate.c>
#AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css application/x-javascript application/javascript
AddOutputFilterByType DEFLATE text/css application/x-javascript text/x-component text/html text/richtext image/svg+xml text/plain text/xsd text/xsl text/xml image/x-icon application/javascript
<IfModule mod_setenvif.c>
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
</IfModule>
<IfModule mod_headers.c>
Header append Vary User-Agent env=!dont-vary
</IfModule>
</IfModule>
<IfModule mod_deflate.c>
SetOutputFilter DEFLATE
<IfModule mod_setenvif.c>
SetEnvIfNoCase Request_URI \.(?:rar|zip)$ no-gzip dont-vary
SetEnvIfNoCase Request_URI \.(?:gif|jpg|png)$ no-gzip dont-vary
SetEnvIfNoCase Request_URI \.(?:avi|mov|mp4)$ no-gzip dont-vary
SetEnvIfNoCase Request_URI \.mp3$ no-gzip dont-vary
</IfModule>
</IfModule>
<IfModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file \.(html?|txt|css|js|php|pl)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</IfModule>
Header unset Pragma
FileETag None
Header unset ETag
<IfModule mod_headers.c>
Header unset ETag
</IfModule>
FileETag None
<FilesMatch "\.(ico|jpg|jpeg|png|gif|js|css|swf|pdf|flv|mp3)$">
<IfModule mod_expires.c>
ExpiresActive on
ExpiresDefault "access plus 14 days"
Header set Cache-Control "public"
</IfModule>
</FilesMatch>
<FilesMatch "\.(html|htm|xml|txt|xsl)$">
Header set Cache-Control "max-age=7200, must-revalidate"
</FilesMatch>
<IfModule mod_expires.c>
ExpiresActive On
#ExpiresDefault "access plus 1 week"
ExpiresDefault "access plus 86400 seconds"
ExpiresByType image/x-icon "modification plus 1 year"
ExpiresByType image/gif "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/jpg "access plus 1 year"
ExpiresByType text/js "access plus 1 month"
ExpiresByType text/javascript "access plus 1 month"
ExpiresByType application/javascript "access plus 1 month"
ExpiresByType application/x-javascript "access plus 1 month"
ExpiresByType application/x-shockwave-flash "access plus 1 month"
ExpiresByType video/x-flv "access plus 1 month"
ExpiresByType application/pdf "access plus 1 month"
#ExpiresByType text/html "access plus 1 day"
#ExpiresByType text/css "access plus 1 day"
#ExpiresByType application/xhtml+xml "access plus 1 day"
#ExpiresByType text/plain "access plus 1 month"
#ExpiresByType text/javascript "access plus 604800 seconds"
#ExpiresByType application/javascript "access plus 604800 seconds"
</IfModule>
The following line needs updating from:
SetEnvIfNoCase Request_URI \.(?:gif|jpg|png)$ no-gzip dont-vary
to
SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary
You also seem to have some duplication here:
Header unset Pragma
FileETag None
Header unset ETag
<IfModule mod_headers.c>
Header unset ETag
</IfModule>
FileETag None
And additionally, it'd be worth combining your <IfModule> directives, so all the directives for mod_expires are in one location and you should also remove the duplicate expires settings. E.g.
<FilesMatch "\.(ico|jpg|jpeg|png|gif|js|css|swf|pdf|flv|mp3)$">
<IfModule mod_expires.c>
ExpiresActive on
ExpiresDefault "access plus 14 days"
Header set Cache-Control "public"
</IfModule>
</FilesMatch>
gets overwritten by
<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus 86400 seconds"
ExpiresByType image/x-icon "modification plus 1 year"
ExpiresByType image/gif "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/jpg "access plus 1 year"
ExpiresByType text/js "access plus 1 month"
ExpiresByType text/javascript "access plus 1 month"
Other than that, yes.

how to store gzipped files on server with .htaccess setting (apache 2)?

i'm looking for a rule to set on my .htaccess for store a gzipped file on the server when it will gzipped from the server. If is it possible i can save the cpu from always gzip the same files and the server could simply send the gzipped file instead of gzipped it "on the fly".
This is my .htaccess configuration
# BEGIN Compress text files
<ifModule mod_deflate.c>
<filesMatch "\.(css|js|x?html?|php)$">
SetOutputFilter DEFLATE
</filesMatch>
</ifModule>
# END Compress text files
# BEGIN Expire headers
<ifModule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus 1 seconds"
ExpiresByType image/x-icon "access plus 2592000 seconds"
ExpiresByType image/jpeg "access plus 2592000 seconds"
ExpiresByType image/png "access plus 2592000 seconds"
ExpiresByType image/gif "access plus 2592000 seconds"
ExpiresByType application/x-shockwave-flash "access plus 2592000 seconds"
ExpiresByType text/css "access plus 604800 seconds"
ExpiresByType text/javascript "access plus 216000 seconds"
ExpiresByType application/javascript "access plus 216000 seconds"
ExpiresByType application/x-javascript "access plus 216000 seconds"
ExpiresByType text/html "access plus 600 seconds"
ExpiresByType application/xhtml+xml "access plus 600 seconds"
</ifModule>
# END Expire headers
# BEGIN Cache-Control Headers
<ifModule mod_headers.c>
<filesMatch "\.(ico|jpe?g|png|gif|swf)$">
Header set Cache-Control "max-age=2592000, public"
</filesMatch>
<filesMatch "\.(css)$">
Header set Cache-Control "max-age=604800, public"
</filesMatch>
<filesMatch "\.(js)$">
Header set Cache-Control "max-age=216000, private"
</filesMatch>
<filesMatch "\.(x?html?|php)$">
Header set Cache-Control "max-age=600, private, must-revalidate"
</filesMatch>
</ifModule>
# END Cache-Control Headers
# BEGIN Turn ETags Off
<ifModule mod_headers.c>
Header unset ETag
</ifModule>
FileETag None
# END Turn ETags Off
# BEGIN Remove Last-Modified Header
<ifModule mod_headers.c>
Header unset Last-Modified
</ifModule>
# END Remove Last-Modified Header
thanks

Apache Deflate on CSS and JS in subdirectory - No Compression

Website: http://taylorsbackyardcenter.ca/store
So I'm finishing an OSCommerce site and I'm implementing compression, caching, and site optimization. I have run into a problem with deflate.
Both Page Speed and YSlow inform me that:
Compressing http://taylorsbackyardcenter.ca/store/includes/functions/js/jquery.min.js could save 46.5KiB (65% reduction).
Compressing http://taylorsbackyardcenter.ca/store/includes/sts_templates/taylor/taylor_stylesheet.css could save 9.7KiB (79% reduction).
I think my .htaccess file is correct:
#############################
## Site Speed/Optimization ##
#############################
# MIME Type Fixes
AddType image/x-icon .ico
AddType text/javascript .js
AddType text/css .css
#############################
# Compress
SetOutputFilter DEFLATE
AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css
AddOutputFilterByType DEFLATE text/javascript application/x-javascript application/javascript
#############################
# Proxy fix
Header append Vary User-Agent env=!dont-vary
# Set ETag
FileETag MTime Size
# Public Caching
Header set Cache-Control "public, no-transform"
# Expires Headers
ExpiresActive on
ExpiresByType text/html "access plus 30 seconds"
ExpiresByType text/css "access plus 3 months"
ExpiresByType text/javascript "access plus 1 year"
ExpiresByType application/javascript "access plus 1 year"
ExpiresByType image/gif "access plus 3 months"
ExpiresByType image/jpeg "access plus 3 months"
ExpiresByType image/png "access plus 3 months"
ExpiresByType image/x-icon "access plus 1 year"
#############################
Please advise
Generally they mean mini-fying, or removing useless empty space, there should be a link that says view optimized version or download optimized version. Just save it over top of your old one and upload it to your server. That should take care of it.