mod_rewrite not working in openSUSE

I have the following rule on one of my sites:

RewriteEngine On
RewriteRule ^([0-9a-zA-Z\-]*)(/?)([0-9a-zA-Z\-\+\_\']*)(/?)([0-9a-zA-Z\-\+\_\%\']*)(/?)([0-9a-zA-Z\-\+\_\%\']*)(/?)([0-9a-zA-Z\-]*)(/?)$ index.php?id1=$1&id2=$3&id3=$5&id4=$7&id5=$9

The aim is to redirect the following:

http://www.example.com/europe/uk/england/bristol/clifton/

to this:

http://www.example.com/index.php?id1=europe&id2=uk&id3=england&id4=bristol&id5=clifton

However, it should also rewrite shorter URIs, e.g.:

http://www.example.com/europe/uk/england/

should become:

http://www.example.com/index.php?id1=europe&id2=uk&id3=england

It all works fine on my live server and in WAMP on my local machine. I just installed openSUSE 11.3 on another computer and found out that this mod_rewrite rule doesn’t work there. I am 100% sure mod_rewrite is working fine on this machine since I’ve tested it with other, simpler rules. I’m thinking perhaps the syntax of the rule isn’t right and openSUSE with Apache2 is less forgiving? Any ideas? Thanks.

I admit I’ve never used a rule that complicated but my first thought was to turn on any debugging available in mod_rewrite. For example a search on “debugging mod_rewrite” turned up this:

http://www.latenightpc.com/blog/archives/2007/09/05/a-couple-ways-to-debug-mod_rewrite

Thanks, will try the debugging.

The rule could probably be much simpler - I’m just not good enough in reg expressions, mod_rewrite, apache and things to optimise it better. I tried a much simpler version too:

RewriteEngine on
RewriteRule ^(.*)/(.*)/(.*)/(.*)/(.*)/$ index.php?id1=$1&id2=$2&id3=$3&id4=$4&id5=$5 [L]

This works if all 5 variables are defined but doesn’t work for fewer than that, e.g. it doesn’t work for:

http://www.example.com/europe/uk/england/

Any ideas how to make it accept less variables than 5 as well?

Well you can see that the problem is that the RE must have at least 5 slashes, otherwise it won’t match. You have to write a RE where the 4th and 5th terms are optional. Instead of trying to do it all in one line, why not have a second rule that matches 4 terms, and a third rule that matches 3 terms, and cascade down the chain until a match is found, or not.

Cascading down the rules helped, thank you very much!