Results 1 to 5 of 5

Thread: mod_rewrite not working in openSUSE

Hybrid View

  1. #1

    Default mod_rewrite not working in openSUSE

    I have the following rule on one of my sites:

    Code:
    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:

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

    Code:
    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.:

    Code:
    http://www.example.com/europe/uk/england/
    should become:

    Code:
    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.

  2. #2
    Join Date
    Jun 2008
    Location
    UTC+10
    Posts
    9,686
    Blog Entries
    4

    Default Re: mod_rewrite not working in openSUSE

    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/arch...ug-mod_rewrite

  3. #3

    Default Re: mod_rewrite not working in openSUSE

    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:

    Code:
    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:

    Code:
    http://www.example.com/europe/uk/england/
    Any ideas how to make it accept less variables than 5 as well?

  4. #4
    Join Date
    Jun 2008
    Location
    UTC+10
    Posts
    9,686
    Blog Entries
    4

    Default Re: mod_rewrite not working in openSUSE

    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.

  5. #5

    Default Re: mod_rewrite not working in openSUSE

    Cascading down the rules helped, thank you very much!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •