我有:

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


如何将所有文件类型重写为:

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




非常感谢。

最佳答案

类似于下面的内容应该起作用。

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]


您可能需要根据具体情况进行调整。注意捕获组((js/*\.js))的用法,用于存储要在目标($1)中使用的可变路径信息。还要注意NCRL选项;分别代表“无大小写”(不区分大小写),“重定向”(重定向请求)和“最后一条规则”(如果此规则匹配则停止处理其他规则)。

09-30 13:34
查看更多