简体   繁体   English

如何将所有JS,CSS,IMG重写为静态子域?

[英]How rewrite all JS, CSS, IMG to static subdomain?

I have: 我有:

sub.domain.com/js/test.js
sub.domain.com/image1.jpg
sub.domain.com/test.css

How rewrite all the file types to: 如何将所有文件类型重写为:

static-sub.domain.com/....

?

Thanks a lot. 非常感谢。

Something akin to what's below should work. 类似于下面的内容应该起作用。

RewriteEngine on
RewriteRule ^sub\.domain\.com/(js/*\.js)$ static-sub.domain.com/$1 [NC,R,L]
RewriteRule ^sub\.domain\.com/(*\.jpg)$ static-sub.domain.com/$1 [NC,R,L]
RewriteRule ^sub\.domain\.com/(*\.css)$ static-sub.domain.com/$1 [NC,R,L]

You'll likely need to tweak it to your specific scenario. 您可能需要根据具体情况进行调整。 Notice the usage of capturing groups ( (js/*\\.js) ) to store the variable path information to be used in the destination ( $1 ). 注意捕获组( (js/*\\.js) )的用法,用于存储要在目标( $1 )中使用的变量路径信息。 Also note the NC , R and L options; 还要注意NCRL选项; which stand for "no casing" (case insensetive), "redirect" (redirect the request) and "last rule" (stop processing further rules if this rule is a match). 代表“无大小写”(不区分大小写),“重定向”(重定向请求)和“最后一条规则”(如果此规则匹配则停止处理其他规则)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM