URL Rewrite Rule using .htaccess not working as expected

In continuation with my previous Question url-rewrite-rule-based-on-certain-conditions
I am trying to do a URL rewrite like this

http://www.mydomain.com/wp-content/plugins/pluginA/abc.css
http://www.mydomain.com/wp-content/plugins/pluginA/abc.js

i want that when the CSS and JS are from this plugin (Plugin A ) or any other plugin whose URL i want to rewrite, The URL should get rewritten as

Read More
http://www.cdn.mydomain.com/wp-content/plugins/pluginA/abc.css
http://www.cdn.mydomain.com/wp-content/plugins/pluginA/abc.js

This is what i tried as in my .htaccess file

<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteBase /wordpress/
RewriteCond %{QUERY_STRING} (<|%3C).*script.*(>|%3E) [NC,OR]
RewriteCond %{QUERY_STRING} GLOBALS(=|[|%[0-9A-Z]{0,2}) [OR]
RewriteCond %{QUERY_STRING} _REQUEST(=|[|%[0-9A-Z]{0,2})
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} ^.+.(css|js)$
RewriteRule ^wp-content/plugins/(nivo-slider-light|Usernoise|lightbox-plus|wp-content-slideshow|content-slide)/(.+)$ http:/abc.cloudfront.net/wp-content/plugins/$1/$2 [L,R=302,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wordpress/index.php [L]
</IfModule>

I have tried every possible way to rewrite the URL so that JS and CSS should get served from my CDN server, but seems like the rule is never been picked up by apache.Any help/pointer in this regard will really be appreciated.

Related posts

Leave a Reply

1 comment

  1. Make this your first rule (right after RewriteBase line)

    RewriteRule ^(wp-content/plugins/(nivo-slider-light|Usernoise|lightbox-plus|wp-content-slideshow|content-slide)/[^.]+.(css|js))$ http://abc.cloudfront.net/$1 [L,R,NC]
    

    Also if it doesn’t work try moving your *.js and *.css files away from local directories under wp-content/plugins/ path.