2017-04-06 41 views
0

我試圖調試一些Apache配置的問題,但我不能讓Apache重寫工作時使用RewriteMap。正確使用RewriteMap時的Apache RewriteCond和RewriteRule?

這是/etc/apache2/map.txt

/21.html /1.html 
/22.html www.localhost/2.html 
www.localhost/23.html www.localhost/3.html 
/23.html?blabla=bla /4.html 

裏面的內容來測試這個我提供一對夫婦的HTML頁面與小腳本:

#!/bin/bash 

COUNTER=1 

while [ $COUNTER -lt 20 ]; do 
echo "<html> 
<body> 

<h1>PAGE NR $COUNTER</h1> 

<p>My first paragraph.</p> 

</body> 
</html>" > /var/www/$COUNTER.html 
let COUNTER=COUNTER+1 
done 

我幾乎嘗試過每多我在論壇/谷歌找到的變體,但沒有人可以使我的RewriteCond和RewriteRule工作。

我不知道我的虛擬主機內的正確設置:

RewriteEngine on 
RewriteMap map "/etc/apache2/map.txt" 
RewriteCond ??????? 
RewriteRule ??????? 

我不是很確定,但我想我應該有多個的RewriteCond重寫規則和匹配從地圖文件中的所有這些diferent線。

另外我真的沒有得到如何匹配的條件/規則使用地圖文件中的值。在一些例子中,人們提到1美元和2美元,有些則不提。

任何幫助,非常感謝

回答

0

那些條件/那得到的東西的工作細則:

RewriteCond %{REQUEST_URI}     ^(/.*[^/])/?$ 
RewriteCond %{QUERY_STRING}  !.+ 
RewriteCond ${map:${lc:%1}|NOT_FOUND} !NOT_FOUND 
RewriteRule .+ ${map:${lc:%1}}?     [NC,L,R] 

RewriteCond %{REQUEST_URI}     ^(/.*[^/])/?$ 
RewriteCond %{QUERY_STRING}  ^.+ 
RewriteCond ${map:${lc:%{REQUEST_URI}?%{QUERY_STRING}}|NOT_FOUND} !NOT_FOUND 
RewriteRule .+ ${map:${lc:%{REQUEST_URI}?%{QUERY_STRING}}} [NC,L,R] 
相關問題