Welcome to WebmasterWorld Guest from

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Problem chaining rewriterules



2:47 am on Aug 15, 2007 (gmt 0)

5+ Year Member


I am having problems using more than 8 variables and I see that apache can only handle 8 and it is possible to chain rewriterules together.

I read a post on this forum where this example was given

#rewriterule ^product([^-]+)-([^-]+)-([^-]+)-([^-]+)-([^-]+)-([^-]+)-([^-]+)-([^-]+)-(.+)$ /script.php.$9?v1=$1&v2=$2&v3=$3&v4=$4&v5=$5&v6=$6&v7=$7&v8=$8 [C]
#rewriterule ^script\.php\.([^-]+)-([^-]+)-([^-]+)-([^-]+)no dash$ /script.php?v9=$1&v10=$2&v11=$3&v12=$4& [QSA,L]

I am trying to use the same logic with the beneath rule. (This rule would normally work, were it not for that pesky apache limitation!)

RewriteRule ^/?([-a-zA-Z0-9_\-]+)/([-a-zA-Z0-9_\-]+)/([a-zA-Z0-9]+)-([a-zA-Z0-9_\-]+)/([a-zA-Z0-9]+)-([a-zA-Z0-9_\-]+)/([a-zA-Z0-9]+)-([a-zA-Z0-9_\-]+)/([a-zA-Z0-9]+)-([a-zA-Z0-9_\-]+)/?$ index.php?sectionnameurl=$1&categorynameurl=$2&geta=$3&geturla=$4&getb=$5&geturlb=$6&getc=$7&geturlc=$8&getd=$9&geturld=$10 [NC]

Here is my attempt at converting the above rewriterule to the chained logic in the first example.

RewriteRule ^/?([a-zA-Z0-9_\-]+)/([a-zA-Z0-9_\-]+)/([a-zA-Z0-9]+)-([a-zA-Z0-9_\-]+)/([a-zA-Z0-9]+)-([a-zA-Z0-9_\-]+)/([a-zA-Z0-9]+)-([a-zA-Z0-9_\-]+)/$ index.php.$9?sec=$1&cat=$2&geta=$3&geturla=$4&getb=$5&geturlb=$6&getc=$7&geturlc=$8 [C]
RewriteRule ^([a-zA-Z0-9]+)-([a-zA-Z0-9_\-]+)$ /index.php?getd=$1&geturld=$2 [QSA,L]

I cant seem to get it to work no matter how hard i try :(

Any help is much appreciated




2:51 pm on Aug 15, 2007 (gmt 0)

5+ Year Member

Still really struggling with this.

I get a 404 error no matter which combination I use.

Should I move this work out of htaccess and into my script?

The only problem with this is that I will still run out of variables at some point, because there are more (around 12 in total)

Really appreciate any advice as to how to tackle this.




4:07 pm on Aug 15, 2007 (gmt 0)

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

The pattern of the second rule must match the URL as rewritten by the first rule, otherwise, it will never be applied. Look at the example you worked from: The first rule rewrites to an intermediate URL (script.php), puts any name/values that won't fit into the first eight variables ($1-$8) into variable $9 and then back-references $9 in the substitution URL, so that the second rule can parse those additional name/values.

Note that "script.php" need not be a real URL or a real file -- it is just used as a unique temporary name while we step through the chained rules.



6:07 pm on Aug 15, 2007 (gmt 0)

5+ Year Member

Thanks a lot for the help with this.

There is really not a lot of information about how to do things like this in apache.

Very much appreciated



Featured Threads

Hot Threads This Week

Hot Threads This Month