Help with Regular Expression (REGEX)

Discussion in 'PHP' started by NaSh123, Oct 26, 2009.

  1. #1
    NaSh123, Oct 26, 2009 IP
  2. NaSh123

    NaSh123 Peon

    Messages:
    1,298
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I've tried using

    /page/[0-9]+/?s=*

    and pointing it to

    /?s=*

    But it didn't work. Thanks guys!
     
    NaSh123, Oct 26, 2009 IP
  3. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #3
    How and where are you matching them? .htaccess? Within the pages? ...?

    Anyway, the pattern would be something like:
    
    '~^http://(www\.)?site\.com/([\w-]+/)?page/\d+/\?s=(.*?)$~'
    
    PHP:
     
    nico_swd, Oct 27, 2009 IP
  4. eamong

    eamong Well-Known Member

    Messages:
    33
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    108
    #4
    sometimes querystring is to be checked separately
    
    RewriteCond %{QUERY_STRING}	^(.*)s=(.*)$
    RewriteRule ^(category)?/page/number/$ /?s=%2	
    
    Code (markup):
     
    eamong, Oct 28, 2009 IP
  5. NaSh123

    NaSh123 Peon

    Messages:
    1,298
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Thanks guys! Got it to work, my problem was I forgot to escape the ? character.

    I used

    /page/(0-9)+/\?s=*

    And 301 redirect it to

    /?s=*

    I was using this in the WordPress redirection plugin.
     
    NaSh123, Oct 28, 2009 IP