Demuri Celidze Demuri Celidze - 1 year ago 103
Apache Configuration Question

How to rewrite paths for certain file types with .htaccess?

I move my static files to CDN. There are images, fonts, js, css, and some of them include paths to other files. E.g. file
will be at
, and it contain path like
How to rewrite all those paths with .htaccess?

Answer Source

The following code should work:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^site\.com$ [NC]
RewriteCond %{REQUEST_URI} \.(jpe?g|png|svg|css|js|eot|ttf|woff2?)$ [NC]
RewriteRule ^{REQUEST_URI} [R=301,L]

Keep adding other file extensions to the 2nd RewriteCond directive above.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download