Forum Moderators: phranque

Message Too Old, No Replies

Little RewriteRule problem

         

smagdy

10:51 am on Jun 5, 2005 (gmt 0)

10+ Year Member



hi everybody..

Ive this in .htaaccess

RewriteRule ^mob/([a-zA-Z-]+)-opinions-([0-9-]+)-([0-9-]+)-([0-9-]+)$ mob/allopinions.php?phone=$1&c=$2&limit=$3&page=$4

so it should return something like

nokia-opinions-1-12-2

and it returns it fine

but when i get the value of

$c, $limit, $page

which should be
$c = 1
$limit = 12
$page = 2

it returns
$c = 1-12-2

and the other 2 are empty

so how is that?

Thanks in advance

smagdy

3:50 pm on Jun 5, 2005 (gmt 0)

10+ Year Member



anybody please help!

jd01

8:27 pm on Jun 5, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi smagdy,

This ([0-9-]+) matches any number from 0 to 9 OR - 1 or more times, so, it matches the entire string you are trying to match with this ([0-9-]+)-([0-9-]+)-([0-9-]+) IOW all the numbers are being stored in the first variable.

The correction would be ([0-9]+)-([0-9]+)-([0-9]+)

Hope this helps.

Justin

smagdy

12:07 pm on Jun 6, 2005 (gmt 0)

10+ Year Member



I changed it but its just the same problem!

what should I change?

smagdy

12:10 pm on Jun 6, 2005 (gmt 0)

10+ Year Member



I've this one above it and working fine..

RewriteRule ^mob/([a-zA-Z-]+)-([0-9-]+)-([0-9-]+)-([0-9-]+)$ mob/phones.php?brand=$1&c=$2&limit=$3&page=$4

its working fine with the extra dash!

jd01

1:30 pm on Jun 6, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This rule:

RewriteRule ^mob/([a-zA-Z-]+)-([0-9-]+)-([0-9-]+)-([0-9-]+)$ mob/phones.php?brand=$1&c=$2&limit=$3&page=$4

Catches both:
nokia-opinions-1-12-2
nokia-1-12-2

Justin

I recommend the regular expression tutorial in the forum charter.

smagdy

4:13 pm on Jun 6, 2005 (gmt 0)

10+ Year Member



i didnt get it.. where is the forum charter?

smagdy

9:18 pm on Jun 6, 2005 (gmt 0)

10+ Year Member



I changed some in my rules cuz i think there was a conflict..

so now i want this to work, It gives
"HTTP 404 not found"

This is the rule:

RewriteRule ^([a-zA-Z-]+)-([0-9-]+)-([0-9-]+)-([0-9-]+)-opinions$ allopinions.php?phone=$1&c=$2&limit=$3&page=$4

This is the link:

[mysite.com...]

am really getting crazy.. I cant find where is the mistake!

the allopinions.php is there and the link works when i write it like this:

[mysite.com...]

PLease help! thanks in advance

jd01

1:04 am on Jun 7, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The problem with the protion of the file you are posting, is really the regular expressions, I am not guessing or making it up... Promise.

I cannot see your whole file, so I do not know what other conflicts, or catches there may be in the rules/conditions/regular expressions, but the correction for the regular expression I posted earlier is correct.

The forum charter is right above the Apache Web Server title on this page, here is a link:
[webmasterworld.com...]

You can also find more information here: (See page 2 message #13)
[webmasterworld.com...]

Wish I could tell you something different, but ([0-9-]+) matches and stores 1 or more of '0 to 9 or -' until there is a character in the string that does not match, a break in the line (EG space) or the line ends.

Justin

smagdy

10:35 am on Jun 7, 2005 (gmt 0)

10+ Year Member



I solved the problem.. its so funny how u can be crazy for 2 days just cuz u missed somethin little as this!

I had to write

([a-zA-Z0-9-]+)

instead of

([a-zA-Z-]+)

because the name contained numbers!

Anyways thanks a lot for ur time