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

    
Chained rewriterule problem with last parameters
Zacharias




msg:3424942
 5:53 pm on Aug 17, 2007 (gmt 0)

Hi,

I cant seem to get these two rules to work together.

The first is the actual page and the second is the paginated page.

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_/-]+)/([a-zA-Z0-9]+)-([a-zA-Z0-9_/-]+)/$ script.php.$9?sec=$1&cat=$2&geta=$3&geturla=$4&getb=$5&geturlb=$6&getc=$7&geturlc=$8 [C]
rewriterule ^script\.php\.([a-zA-Z0-9_/-]+)/([a-zA-Z0-9]+)-([a-zA-Z0-9_/-]+)/([a-zA-Z0-9]+)-([a-zA-Z0-9_/-]+)/$ /testtd/index.php?var=$1&getd=$2&geturld=$3&gete=$4&geturle=$5 [QSA,L]

#page
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_/-]+)/([a-zA-Z0-9]+)-([a-zA-Z0-9_/-]+)/$ script.php.$9?sec=$1&cat=$2&geta=$3&geturla=$4&getb=$5&geturlb=$6&getc=$7&geturlc=$8 [C]
rewriterule ^script\.php\.([a-zA-Z0-9_/-]+)/([a-zA-Z0-9]+)-([a-zA-Z0-9_/-]+)/([a-zA-Z0-9]+)-([a-zA-Z0-9_/-]+)/_([0-9]+)/$ /testtd/index.php?var=$1&getd=$2&geturld=$3&gete=$4&geturle=$5&page=$6 [QSA,L]

Is it because the first part in the chain, the condition is met and therefore only the 1st rule works?

Cheers

Z

 

g1smd




msg:3424971
 6:15 pm on Aug 17, 2007 (gmt 0)

If you have two rules: one for a specific condition, and another for all the others, then the specific one goes first.

Zacharias




msg:3425001
 6:40 pm on Aug 17, 2007 (gmt 0)

ive tried changing the order and it doesnt work

I felt it might have something to do with the first part in the chain condition being met in the first rule and therefore the first rule applying to both sets of pages, no?

I am wondering if it is possible to use a rewritecond to check if a parameter or character (in my case an underscore) exists in the query string and then append &page= to the end of the rewrite rule. This would achieve what I want,however im not sure how to write it.

Any help is much appreciated

cheers

z

jdMorgan




msg:3425037
 7:21 pm on Aug 17, 2007 (gmt 0)

You cannot include "/" within the [a-z0-9_-] alternate character groups used to match your parameters without fatally confusing the regex parser. If you do, the first rule of both rule sets will always match, but the second rule will never match, and therefore both chained sets will fail as a whole. This is because the "+" quantifier is greedy, and each subpattern will match as many characters as possible, leaving the second rule to 'starve' in both cases.

Generalizing, you cannot use a character as a substring separator while also using it inside the substring to be separated.

You also have too many parentheses in the the first rule of both chained sets. You may use nine pairs, and no more. Use the ninth pair to grab *everything* that won't fit in the first eight pairs.

You can make good use of the [NC] flag to simplify your patterns, and make them somewhat more tolerable to read and interpret for those brave souls who care to undertake the task... The [NC] flag makes the pattern-matching case-insensitive, which means you can use just [A-Z] or [a-z] in each of the subpatterns, instead of having to use [A-Za-z] in each one.

Cleaning up the separator/parameter and too-many-parentheses problems, adding the [NC] flag, putting the rules in order, and tidying-up in general, I'd recommend something like this:

# paged
RewriteRule ^([a-z0-9_-]+)/([a-z0-9_-]+)/([a-z0-9]+)-([a-z0-9_-]+)/([a-z0-9]+)-([a-z0-9_-]+)/([a-z0-9]+)-([a-z0-9_-]+)/([a-z0-9]+-[a-z0-9_-]+/[a-z0-9]+-[a-z0-9_-]+)/$ tempurl/$9?sec=$1&cat=$2&geta=$3&geturla=$4&getb=$5&geturlb=$6&getc=$7&geturlc=$8 [NC,C]
RewriteRule ^tempurl/([a-z0-9_-]+)/([a-z0-9]+)-([a-z0-9_-]+)/([a-z0-9]+)-([a-z0-9_-]+)/_([0-9]+)$ /testtd/index.php?var=$1&getd=$2&geturld=$3&gete=$4&geturle=$5&page=$6 [NC,QSA,L]
#
# non-paged
RewriteRule
^([a-z0-9_-]+)/([a-z0-9_-]+)/([a-z0-9]+)-([a-z0-9_-]+)/([a-z0-9]+)-([a-z0-9_-]+)/([a-z0-9]+)-([a-z0-9_-]+)/([a-z0-9]+-[a-z0-9_-]+/[a-z0-9]+-[a-z0-9_-]+)/$ tempurl/$9?sec=$1&cat=$2&geta=$3&geturla=$4&getb=$5&geturlb=$6&getc=$7&geturlc=$8 [NC,C]
RewriteRule ^tempurl/([a-z0-9_/-]+)/([a-z0-9]+)-([a-z0-9_/-]+)/([a-z0-9]+)-([a-z0-9_/-]+)$ /testtd/index.php?var=$1&getd=$2&geturld=$3&gete=$4&geturle=$5 [NC,QSA,L]

Note that since the "filename" created by the first chained rule is temporary and does not exist as a real file (we hope), I have given it a name that implies that it's just an intermediate step, and not a real URL-path.

I may have typoed or fat-finger-deleted something unintentionally. Check carefully and test thoroughly.

Jim

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