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="https://wordpress.stackexchange.com/questions/280857/<?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"
</IfModule>
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]
</IfModule>

# 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="http://ask.prosentra.com/wp-content/themes/tutorialblog/assets/css/main.1504604028.css" rel="stylesheet" type="text/css">

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

2 Answers
2

This is a dead end approch as the enqueue API do not support such versioning format which means that you will have to avoid using it, which is not a great thing. Your specific problem here is that you added the rule too late, RewriteRule . /index.php [L] “transfers” handling to wordpress and nothing is going to be done after that, which means that you need to switch the order of them. And again changing the wordpress core rewrite rules is not smart, you should probably add a specific section outside of the wordpress rules section.

Leave a Reply

Your email address will not be published. Required fields are marked *