Demuri Celidze
Demuri Celidze

Reputation: 615

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 site.com/fonts/fontname.css will be at static.othersite.com/folder/fonts/fontname.css, and it contain path like src:url(fontname.eot). How to rewrite all those paths with .htaccess?

Upvotes: 1

Views: 842

Answers (1)

hjpotter92
hjpotter92

Reputation: 80639

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 ^ http://static.othersite.com/folder%{REQUEST_URI} [R=301,L]

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

Upvotes: 1

Related Questions