Welcome to WebmasterWorld Guest from 54.160.221.82

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

mod rewrite not working in openSUSE

Works in WAMP and on live server but not in openSUSE

     
10:41 am on Nov 21, 2010 (gmt 0)

New User

10+ Year Member

joined:June 5, 2005
posts: 31
votes: 0


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.
7:53 pm on Nov 21, 2010 (gmt 0)

Senior Member

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:July 3, 2002
posts:18903
votes: 0


First off we need to clarify whether you want a redirect or rewrite.

You've used these two terms interchangeably, but they are two completely different things (even though the code for them is very similar).
9:04 pm on Nov 21, 2010 (gmt 0)

New User

10+ Year Member

joined:June 5, 2005
posts: 31
votes: 0


Sorry, I mean URL rewrite.

I found out this fixed the issue:


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


Might not be the best solution but it seems to work.
4:16 am on Nov 30, 2010 (gmt 0)

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
posts:25430
votes: 0


Server been a bit slow these past ten days when it's busy?

You can significantly speed up your rules by using a much-more-specific pattern.

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

And now that the patterns are specific, you are now free to order these rules from most- to least-requested, for a further (if smaller) increase in server performance. Use your server 'stats' to determine which form of URLs are most-requested, and which are least-requested, then order the rules based on that.

Do not use multiple "dot-star" subpatterns unless there is absolutely no other solution. To do so forces your server to do hundreds to tens of thousands of 'back-off-and-retry' pattern-matching attempts for every object requested from your server. Conversely, use of specific subpatterns allows the pattern to be evaluated in a single left-to-right pass.

Jim
1:26 pm on Dec 1, 2010 (gmt 0)

New User

10+ Year Member

joined:June 5, 2005
posts: 31
votes: 0


Thanks Jim, you're a star!