Forum Moderators: phranque

Message Too Old, No Replies

Need help with RewriteRule

problem with the regexp

         

jurma

4:41 pm on Jun 9, 2010 (gmt 0)

10+ Year Member



Hi everyone here.
I hope for any help to make a RewriteRule for my .htaccess file.
I need to redirect all urls with given mask to one file.

The initial address is: http://www.example.com/index.php?p=21-122-116

The mask is: index.php?p=21-122-116.

This mask (21-122-116) I need to pass to the target file.
Here is a rule I'm writting (I used PCRE standard for it):
RewriteRule index\.php\?p=([\d]{1,3})-([\d]{1,3})-([\d]{1,3}) uwrite.php?productid=$1&$2&$3
But it does not work :( Just no match.

I tried to play around with it but only this works:
RewriteRule index\.php uwrite.php?productid=$1
but any other additions after index\.php causes no match of the rule.

Please tell me where I'm wrong and how this have to look.
Thank you in advance..

[edited by: jdMorgan at 5:58 pm (utc) on Jun 9, 2010]
[edit reason] example.com [/edit]

jdMorgan

6:03 pm on Jun 9, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The RewriteRule 'sees' only the requested URL-path, not any query string appended to it. You must use a RewriteCond to test query strings.

RewriteCond %{QUERY_STRING} ^p=([\d]{1,3})-([\d]{1,3})-([\d]{1,3})$
RewriteRule ^index\.php$ uwrite.php?productid=%1&%2&%3 [L]

If you are on Apache 1.x, then you cannot use PCRE, and should use POSIX 1003.2 regular expressions instead.

Jim

jurma

6:16 pm on Jun 9, 2010 (gmt 0)

10+ Year Member



Thank you very much!
This helped me!
Yury