Cache Busting using htaccess Rewrite rule?


I am trying to follow this tutorial that says i can make a server to send a file like style.css if the requested file is style.15458888.css with a rewrite rule to be put inside the htaccess file.

This Rule

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+).(d+).(js|css)$ $1.$3 [L]

So i followed with this in the head tag:

<?php $time = filemtime(get_template_directory() .'/assets/css/main.css');?>
<link href="<?php echo get_template_directory_uri().'/assets/css/main.'.$time.'.css'?>" rel="stylesheet" type="text/css">

and this inside the Htaccess:

    # BEGIN WordPress
<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType image/jpg "access plus 6 hours"
    ExpiresByType image/jpeg "access plus 6 hours"
    ExpiresByType image/gif "access plus 6 hours"
    ExpiresByType image/png "access plus 6 hours"
    ExpiresByType text/css "access plus 6 hours"
    ExpiresByType application/pdf "access plus 1 week"
    ExpiresByType text/javascript "access plus 6 hours"
    ExpiresByType text/html "access plus 10 minutes"
    ExpiresByType image/x-icon "access plus 1 year"
    ExpiresDefault "access plus 3 hours"
Header set X-Endurance-Cache-Level "2"
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteRule ^(.+).(d+).(js|css)$ $1.$3 [L]

# END WordPress

As you can see the RewriteRule ^(.+).(d+).(js|css)$ $1.$3 [L] has been added before the </IfModule>

And the file name changed correctly having this:

<link href="" rel="stylesheet" type="text/css">

But still the server doesn’t implement the rule i mentioned. What is wrong?

, , , , Mohamed Omar 5 months 0 Answers 63 views 0

Leave an answer