0

Im trying to debug an issue with some apache config, but i cant get the apache rewrite to work when using RewriteMap.

this is the content inside /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

to test this i provided a couple html pages with a little script:

#!/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

i tried pretty much every variation i found in the forums/google, but none could bring my RewriteCond and RewriteRule to work.

i dont know the correct setup inside my virtualhost:

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

im not really sure, but i think i should have multiple RewriteCond and RewriteRule to match all those diferent lines from the map file.

Also i really dont get how to match the Condition/Rule using the values from map file. In some examples people refer to $1 and $2 and some dont.

Any help is really appreciated

CayoM
  • 19
  • 6

1 Answers1

0

those are the conditions/rules that got things working:

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]
CayoM
  • 19
  • 6