假设我有以下网址:
site/DB/guest/picture/25-298.jpg?v=140913231208
site/DB/guest/picture/25.jpg?v=140913231208
site/DB/user/cover/27-40.jpg?v=160913051508
site/DB/user/cover/27.jpg?v=160913051508
site/JS/main.js?v=160913132025
site/JS/utils/admin.js?v=1602144214027
site/CSS/main.css?v=160913132038
我希望能够通过访问以下网址加载它们:
guest/picture/140913231208/25-298.jpg
guest/picture/140913231208/25.jpg
user/cover/160913051508/27-40.jpg
user/cover/160913051508/27.jpg
js/160913132025/main.js
js/utils/1602144214027/admin.js
css/160913132038/main.css
我试过重写一些规则。但我总是得到Not Found Error。
例如:
RewriteRule ^js/(.*)/(.*).(.*)$ site/JS/$2.$3\?v=$1 [L]
答案 0 :(得分:3)
尝试:
RewriteRule ^guest/picture/([0-9]+)/(.*)$ /site/DB/guest/picture/$2?v=$1 [L,QSA]
RewriteRule ^user/cover/([0-9]+)/(.*)$ /site/DB/user/cover/$2?v=$1 [L,QSA]
RewriteRule ^js/([0-9]+)/(.*)\.js$ /site/JS/$2.js?v=$1 [L,QSA]
RewriteRule ^js/utils/([0-9]+)/(.*)\.js$ /site/JS/utils/$2.js?v=$1 [L,QSA]
RewriteRule ^css/([0-9]+)/(.*)\.css$ /site/CSS/$2.css?v=$1 [L,QSA]
RewriteRule ^(js|css)(/utils)?/([0-9]+)/(.*)$ /$1$2/$4?v=$3 [L,QSA]