I am trying to add support for Vary: Accept-Encoding from whithin my theme’s function.php file.
Please don’t suggest me to use any plugin, because that the only reason why I am trying to implement this from within my theme.
The idea of using insert_with_markers from this StackOverflow discussion: How to add .htaccess code through a function?
Can you please tell me what I have done wrong?
add_action('after_setup_theme','add_htaccess');
function add_htaccess($insertion)
{
$insertion = array(
'# Enable Vary: Accept-Encoding Start',
'<IfModule mod_headers.c>',
'<FilesMatch "\.(js|css|xml|gz)$">',
'Header append Vary: Accept-Encoding',
'</FilesMatch>',
'</IfModule>',
);
$htaccess_file = ABSPATH.'.htaccess';
return insert_with_markers($htaccess_file, '# Testing', (array) $insertion);
}
.htaccess
yourself? What about those using Nginx, lighttpd or cloud services that don't rely on Apache?