Forum Moderators: phranque

Message Too Old, No Replies

Strange Rewriterule

         

neroag

12:30 pm on Jan 14, 2008 (gmt 0)

10+ Year Member



Hi All

i have a rewrite of ..
RewriteRule ^news/test/([0-9]+)\.html$ xnews.php?newsid=$1 [L]
that works a treat

however /test/ can change so i tried ..

RewriteRule ^news/([a-z]+)/([0-9]+)\.html$ xnews.php?newsid=$1 [L]

and now it doesnt work can anyone help plz?

many thanks

phranque

12:59 pm on Jan 14, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



$1 is now the ([a-z]+) capture group so if you still want to use the ([0-9]+) capture group you should use $2 in the substitution string.

neroag

1:55 pm on Jan 14, 2008 (gmt 0)

10+ Year Member



sorry im looking for it to match whatever is in the /test/ so really the /test/ wants to just be a wildcard is that possible?

phranque

2:01 pm on Jan 14, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



right now you are matching one or more consecutive lower case alphabetic characters.
if you want it to match "anything" up to the next forward slash, you could try:
RewriteRule ^news/([^/]+)/([0-9]+)\.html$ xnews.php?newsid=$2 [L]

(you still want to use $2 because it is now the second group.)

jdMorgan

2:54 pm on Jan 14, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If the 'test' field of the requested URL is to be discarded, then the parentheses around the first subpattern are not required.

However, discarding parts of the requested URL can easily cause a duplicate-content "penalty" problem.

Jim