Apache .htaccess:从单独的域提供 .css 文件?
我正在尝试从单独的域为我的网站提供 CSS 文件。
我在我的网站的 .htaccess (在文档根目录中)中有以下条目:
RewriteRule ^templates/*\.css$ http://css.mysite.com/templates/$1 [R=301,L]
目的是简单地匹配:
http://www.mysite.com/templates/default/styles/main.css
... 并将 HTTP 301 重定向发送到:
http://css.mysite.com/templates/default/styles/main.css
但实际被调用的是:(
http://css.mysite.com/templates/.css
我想复制上面的 *.js
并从 js.mysite.com 提供它们,所有 png 和 jpg 并从 img.mysite.com 提供它们。)
任何见解都很棒。我必须承认,htaccess 重写规则似乎总是让我困惑。
I'm trying to serve CSS files for my site from a separate domain.
I've got the following entry in my site's .htaccess (in the document root):
RewriteRule ^templates/*\.css$ http://css.mysite.com/templates/$1 [R=301,L]
With the intention of simply matching:
http://www.mysite.com/templates/default/styles/main.css
… and sending an HTTP 301 redirect to:
http://css.mysite.com/templates/default/styles/main.css
But what's actually getting called is:
http://css.mysite.com/templates/.css
(I'd like to duplicate the above for *.js
and serve them from js.mysite.com and all png & jpgs and serve them from img.mysite.com.)
Any insights would be fantastic. I've got to admit, htaccess rewrite rules always seem to elude me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个并让我知道:
或者更“动态的方式”
这将检查 JS 和 CSS 并根据文件扩展名使用子域:因此 .js 将转到 js.mysite.com,.css 将转到 css .mysite.com 和图像相同,但这些会转到 imgs.mysite.com。
或者更通用:
您重定向以
templates
开头的所有内容Try this and let me know:
or a more "dynamic way"
This one will check for JS and CSS and use the subdomain based on the file extension: so .js will go to js.mysite.com and .css will go to css.mysite.com and same for images but these goes to imgs.mysite.com instead.
or be even more generic:
You redirecting everything that start with
templates