regexp pattern

Discussion in 'Apache' started by thosecars82, Dec 31, 2009.

  1. #1
    Hello

    Would you please tell me any suggestion for a regular expression which includes any string starting with the string "categories/" that takes any string after "categories/" except car and boat?

    That is to say, examples of the strings in my pattern would be:

    "categories/"

    "categories/aaa"

    "categories/cat"

    "categories/car1"

    "categories/boat0"

    And examples of categories not in my pattern would be:

    "categories/car"

    "categories/boat"

    Thanks in advance
     
    thosecars82, Dec 31, 2009 IP
  2. joebert

    joebert Well-Known Member

    Messages:
    2,150
    Likes Received:
    88
    Best Answers:
    0
    Trophy Points:
    145
    #2
    Use RewriteRule as you normally would. Then use RewriteCond along with the %{REQUEST_URI} variable to single out your two special cases.

    Something along these lines.

    RewriteCond %{REQUEST_URI} !car/?$
    RewriteCond %{REQUEST_URI} !boat/?$
    RewriteRule ^categories/(.*)$
    Code (markup):
     
    joebert, Dec 31, 2009 IP
  3. thosecars82

    thosecars82 Member

    Messages:
    81
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    43
    #3
    Thanks but I was looking for something to write it in just one RewriteRule, in case that was possible and something that did accept "car" or "boat" as words in the pattern.
     
    thosecars82, Jan 1, 2010 IP
  4. joebert

    joebert Well-Known Member

    Messages:
    2,150
    Likes Received:
    88
    Best Answers:
    0
    Trophy Points:
    145
    #4
    Modern versions of Apache use Perl-compatible regular expressions with most if not all of the bells and whistles. Are you familiar with the snytax for Perl regex ?

    The only way you're going to do it with just one pattern is to use look-ahead/behind assertions. I'm not even sure those are part of the standard Perl regex library.
     
    joebert, Jan 1, 2010 IP
  5. thosecars82

    thosecars82 Member

    Messages:
    81
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    43
    #5
    ok, it's ok. I am not familiar with Perl regex. But I just thought doing in one line would be more straightforward. It seems I am wrong though. So I will leave it as it is now. Thanks anyways. (SOLVED)
     
    thosecars82, Jan 1, 2010 IP