我将静态文件移动到CDN。有图像,字体,js,css,其中一些包括其他文件的路径。例如。文件site.com/fonts/fontname.css
位于static.othersite.com/folder/fonts/fontname.css
,其中包含src:url(fontname.eot)
之类的路径。
如何使用.htaccess重写所有这些路径?
答案 0 :(得分:1)
以下代码应该有效:
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]
继续向上面的第二个RewriteCond
指令添加其他文件扩展名。