expires header not working drupal - drupal

I am setting expires header in .htaccess file as below
ExpiresActive On
ExpiresDefault A1209600
It works for all the files that are in document root, but I have a separate mounted drive which is used as drupal file system ( private ), where I store my jcarousel images and for these images the expires header are not working.

You private file system will have its own .htaccess file created by Drupal. Try adding the same line there.
SetHandler Drupal_Security_Do_Not_Remove_See_SA_2006_006
Deny from all
Options None
Options +FollowSymLinks
ExpiresActive On
ExpiresDefault A1209600

Related

Wordpress site fails to run after migration via FTP to AWS EC2 Ubuntu with Apache2

I am trying to manually migrate a Wordpress site via FTP to an AWS EC2 instance that runs an Ubuntu 20.04. Due to certain circumstances I cannot use plugins to do the migration. I basically copied the files of the site to the /var/www/my_site folder, and dumped its old database into a new one that I have access to, while setting up Apache2 as a web server.
And even though I tried almost every angle I could think of, the site does not run. Apache2 is able to run some of the initial files, including wp-config.php, but it fails somewhere along the line, and in the wp-blog-header.php file the wp() function fails when it gets called, or it doesn't even gets called.
When running in a browser, the HTTP request 301 redirects to a HTTPS request and it fails premanently. However, there is no indication in the code that a 301 redirect is set anywhere.
The odd things are that with basically the same configuration I am able to run a simple Wordpress installation on the EC2 instance, and the site I am migrating runs on my local Windows 10 environment with XAMPP. On the EC2 instance the site also fails with NginX.
The things I thought that might be variables in configuration are the following:
File and directory ownership
The owner of everything in the web root directory is www-data, and changing permissions of files and directories doesn't change the result, I have tried every variation.
Modules
Modules that are not enabled by default in Apache2 and needed by Wordpress are enabled, like php7.4, rewrite, expire and header.
Apache2 Virtualhost configuration
I took out ServerName and ServerAlias, because right now I am only trying to access the site throught the EC2 instance's IP address. Remember, that the same configuration (apart from the root directory) works for a simple Wordpress installation.
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/my_site
LogLevel debug
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<Directory /var/www/my_site/>
AllowOverride All
Require all granted
</Directory>
.htaccess files
The main .htaccess file in the project root again is the same as the simple Wordpress installation's.
<IfModule mod_deflate.c>
<FilesMatch "\.(html|php|txt|xml|js|css)$">
SetOutputFilter DEFLATE
</FilesMatch>
</IfModule>
# BEGIN Expire headers
ExpiresActive On
# Images
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/gif "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType image/webp "access plus 1 year"
ExpiresByType image/svg+xml "access plus 1 year"
ExpiresByType image/x-icon "access plus 1 year"
# Video
ExpiresByType video/mp4 "access plus 1 year"
ExpiresByType video/mpeg "access plus 1 year"
# CSS, JavaScript
ExpiresByType text/css "access plus 1 month"
ExpiresByType text/javascript "access plus 1 month"
ExpiresByType application/javascript "access plus 1 month"
# Others
ExpiresByType application/pdf "access plus 1 month"
ExpiresByType application/x-shockwave-flash "access plus 1 month"
# END Expire headers
Header unset ETag
FileETag None
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
However, there were some other .htaccess files elsewhere in other directories. In the wp-includes directory the .htaccess file looked like below, so I removed it.
<Files *.php>
deny from all
</Files>
<Files wp-tinymce.php>
allow from all
</Files>
<Files ms-files.php>
allow from all
</Files>
The other .htaccess files are in different plugin folders, and they don't seem to have any harmful directives.
Database configuration
There are some fields in the database jsdl_options table (in other installation the table name might be wp_options) that need to be set in order for the site to properly function. I also tried many variations, but this is the one that should be good according to other sources, and again, it works for the simple Wordpress installation.
site_url - http://<EC2 instance IP>
home - http://<EC2 instance IP>
upload_path - wp-content/uploads, but full path doesn't work either
wp-config.php
The wp-config.php file is seemingly properly configured. The site manages to connect to the database, it finds the cache location, and finishes reading the file without any issues.
define('WP_CACHE', true);
define( 'WPCACHEHOME', '/var/www/my_site/wp-content/plugins/wp-super-cache/' );
define( 'DB_NAME', 'db' );
define( 'DB_USER', 'dbu' );
define( 'DB_PASSWORD', 'dbp' );
define( 'DB_HOST', 'dbh' );
define( 'DB_CHARSET', 'utf8' );
define( 'DB_COLLATE', '' );
(...)
define('FS_METHOD','direct');
define('FS_CHMOD_DIR',0755);
define('FS_CHMOD_FILE',0644);
define('WP_TEMP_DIR',dirname(__FILE__).'/wp-content/uploads');
(...)
define( 'WP_DEBUG', true );
define ('WP_DEBUG_LOG', '/var/www/my_site/wp-errors.log' );
(...)
Logging
At this level, logging does not help anything. Apache2's debug-level logging does not provide additional information neither in the error.log nor in the access.log files. And the Wordpress logging only catches some unrelated PHP warnings.
Theories
My first theory is that something is blocking access to some internal (e.g. in wp-includes) files.
The other theory is that somewhere along the line there is an SSL configuration, that makes the site not run with simple HTTP requests, and requires HTTPS. But being able to run the site locally proves this otherwise.
So my questions are: Why does the site not run? Why does it fail midway during initialization? Why did it not fail in my local environment?

Need to change a file content type to text/plain so browsers don't prompt for a download and instead show it on the screen

I have a WordPress website hosted on a LiteSpeed server via the Hostinger platform.
I have a file called stellar.toml at www.example.net/.well-known/stellar.toml. The WordPress file manager plugin tells me the file's kind is Plain text.
But if I type its URL I get a download started, I need instead to have the file's text prompted on the screen.
Does anyone know how I can fix this issue?
Thanks in advance!
Create a .htaccess on your .well-known folder:
<IfModule mod_rewrite.c>
<FilesMatch "^stellar\.toml$">
AddType text/plain .toml
</FilesMatch>
</IfModule>

"Add post" sometimes overwriting a previous post Wordpress

I have this issue with my wordpress site, sometimes posting a new post will overwrite a previous post. Specially one of my writers is suffering from this problem very much.
I am using litespeed cache. I've also enabled Redis object caching on my website recently but I had the problem before enabling it too.
I resolved this by adding a htaccess file with below content in wp-admin folder.
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType text/html "access plus 0 seconds"
</IfModule>
RewriteRule ^(.*)$ $1 [NS,E=no-gzip:1,E=dont-vary:1]

Where to create htaccess file for a wordpress site hosted in AWS

Been working on speed optimization for a WordPress site hosted in AWS.
Created .htaccess in the root folder of the site added this
<IfModule mod_expires.c>
<FilesMatch "\.(css|js|png|jpg|jpeg)$">
Header set Cache-Control "max-age=788400, proxy-revalidate"
</FilesMatch>
</IfModule>
Tested the site using GTMetrix, but it still throws 'Leverage Browser Caching'. Seems the htaccess is not taking effect. Is this the right place to put the .htaccess file?

Drupal 7.0 caching problem!

I've just finished a drupal project and I'm going through optimization phase of the site. I've checked cache blocks and CSS and JS aggregation under performance for better load time . but something I noticed, when I run a page speed test or Yslow everything passes but Leverage browser caching. It seems like the expiry date is not set on all the images and css files. My question is do I have to edit .htaccess file or do I need to place the images and css files that are not cached into a particular folder?
Any help is appreciated, many thanks in advance
You can configure Apache to set specific expire / cache control headers for your image/css/js files using mod_expires and mod_headers.
Here are few examples (general examples -- analyse and consult the manual before applying to your system):
<FilesMatch "\.(html|htm|js|css)$">
FileETag None
<IfModule mod_headers.c>
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"
</IfModule>
</FilesMatch>
Caching with both mod_expires + mod_headers
# Turn on Expires and set default to 0
ExpiresActive On
ExpiresDefault A0
# Set up caching on media files for 1 year (forever?)
<FilesMatch "\.(flv|ico|pdf|avi|mov|ppt|doc|mp3|wmv|wav)$">
ExpiresDefault A29030400
Header append Cache-Control "public"
</FilesMatch>
# Set up caching on media files for 1 week
<FilesMatch "\.(gif|jpg|jpeg|png|swf)$">
ExpiresDefault A604800
Header append Cache-Control "public"
</FilesMatch>
# Set up 2 Hour caching on commonly updated files
<FilesMatch "\.(xml|txt|html|js|css)$">
ExpiresDefault A7200
Header append Cache-Control "proxy-revalidate"
</FilesMatch>
# Force no caching for dynamic files
<FilesMatch "\.(php|cgi|pl|htm)$">
ExpiresActive Off
Header set Cache-Control "private, no-cache, no-store, proxy-revalidate, no-transform"
Header set Pragma "no-cache"
</FilesMatch>
I had the same issue for a long time and I just found the trick!
After looking in .htaccess located on drupal's root repository, there is this condition :
<IfModule mod_expires.c> ... </IfModule>
The code located inside is not executed because apache's expires_module is just not enable on my server, check if expires_module is present on list returned by :
sudo apache2ctl -M
If not, just activate it by :
sudo a2enmod expires
sudo a2enmod headers
sudo service apache2 restart

Resources