apache:重写js删除时间戳

时间:2015-10-13 08:39:56

标签: regex apache mod-rewrite

好吧,我想重写js:

/resources/js/general.js/1234/ -> /resources/js/general.js

由于akamai的缓存,我无法使用常规查询字符串:?t = 1234

静态作品:

RewriteRule ^(.*)\.js/[0-9]+/$ /resources/js/general.js [NC,L]

但我无法构建动态正则表达式:(

RewriteRule ^(.*)\.js/[0-9]+/$ $1 [NC,L] 

结果:

/resources/js/general
好吧,但是:

RewriteRule ^(.*)\.js/[0-9]+/$ $1.js [NC,L]

结果:

/resources/js/general.js/1234/

RewriteRule ^(.*)\.js/[0-9]+/$ $1\.js [NC,L]

结果:

/resources/js/general.js/1234/
谢谢你:)

使用所有.htaccess编辑:

AddCharset UTF-8 .php
Options +Includes
XBitHack on
RewriteEngine on

# works static
#RewriteRule ^(.*)\.js/[0-9]+/$ /resources/js/general.js [NC,L]
# not dynamic
RewriteRule ^(.*)\.js/[0-9]+/$ $1.js [NC,L]

1 个答案:

答案 0 :(得分:1)

按此规则替换您的重写规则:

RewriteRule ^(.+?\.js)/\d+/?$ /$1 [NC,L]