homepage Welcome to WebmasterWorld Guest from
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

Problem chaining rewriterules

5+ Year Member

Msg#: 3422403 posted 2:47 am on Aug 15, 2007 (gmt 0)


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





5+ Year Member

Msg#: 3422403 posted 2:51 pm on Aug 15, 2007 (gmt 0)

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.




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

Msg#: 3422403 posted 4:07 pm on Aug 15, 2007 (gmt 0)

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.



5+ Year Member

Msg#: 3422403 posted 6:07 pm on Aug 15, 2007 (gmt 0)

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


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