homepage Welcome to WebmasterWorld Guest from 54.166.255.168
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
mod rewrite not working in openSUSE
Works in WAMP and on live server but not in openSUSE
Jay7

5+ Year Member



 
Msg#: 4232997 posted 10:41 am on Nov 21, 2010 (gmt 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.

 

g1smd

WebmasterWorld Senior Member g1smd us a WebmasterWorld Top Contributor of All Time 10+ Year Member



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

Jay7

5+ Year Member



 
Msg#: 4232997 posted 9:04 pm on Nov 21, 2010 (gmt 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.

jdMorgan

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



 
Msg#: 4232997 posted 4:16 am on Nov 30, 2010 (gmt 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

Jay7

5+ Year Member



 
Msg#: 4232997 posted 1:26 pm on Dec 1, 2010 (gmt 0)

Thanks Jim, you're a star!

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved