2013-09-16 47 views
1

比方說,我有以下網址:的RewriteRules的查詢字符串

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 

我試圖重寫某些規則。但我總是得到未發現的錯誤。

例如:

RewriteRule ^js/(.*)/(.*).(.*)$ site/JS/$2.$3\?v=$1 [L] 
+2

你嘗試什麼規則,什麼線程你指的是 – AD7six

+0

我的意思是問題,而不是主題,編輯! – Hypn0tizeR

+1

您可以在[本頁](http://htaccess.madewithlove.be/)上使用您的重寫規則。 – hjpotter92

回答

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] 
+0

適用於我!有沒有辦法可以在一個RewriteRule中拆分js和css? – Hypn0tizeR

+0

@ Hypn0tizeR嘗試上面的編輯 –

+0

不工作,可能是因爲大小寫,CSS和JS在真正的url中大寫。 – Hypn0tizeR