Problems with RedirectMatch & RegEx

Discussion in 'Apache' started by cyphix, Mar 5, 2008.

  1. #1
    Hey guys.... I'm trying to do something up to match this type of URL:

    video/2-Episode_10_True.html

    But I can't seem to get it working..... my code is below, what am I doing wrong?

    
    RedirectMatch ^video/[0-9]+-([^_\-]_)+.+\.html$ http://www.mydomain.com/
    
    Code (markup):
    So I can learn better can you please explain what I did wrong....

    Thanks!
     
    cyphix, Mar 5, 2008 IP
  2. joebert

    joebert Well-Known Member

    Messages:
    2,150
    Likes Received:
    88
    Best Answers:
    0
    Trophy Points:
    145
    #2
    [^_\-]_
    Code (markup):
    That allows for one character between the first hyphen and the underscore.

    2-E_ would likely match. So would 2-E_p_i_s_o_d_e
     
    joebert, Mar 6, 2008 IP
  3. cyphix

    cyphix Well-Known Member

    Messages:
    245
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    103
    #3
    Ahhhhh I see..... so I should change it to something like this?

    
    RedirectMatch ^video/[0-9]+-([^_\-]+_)+.+\.html$ http://www.mydomain.com/
    
    Code (markup):
    ??

    Thanks!
     
    cyphix, Mar 6, 2008 IP
  4. Cybernaut

    Cybernaut Peon

    Messages:
    408
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #4
    It wont ever match with ^video. The url path starts with a slash. joebert is right too. .+ before \.html is an overkill, [^\.]* was better. Why not try this (make _ optional):

    RedirectMatch video/[0-9]+-([^_\-]+_?)+\.html$ http://www.mydomain.com/
    Code (markup):
    Still, more simple:

    RedirectMatch video/[0-9]+-[^\.]+\.html$ http://www.mydomain.com/
    Code (markup):
    Or if you are sure that files under video/ are definitely videos:

    RedirectMatch video/.*$ http://www.mydomain.com/
    Code (markup):
    Use ^/video if video is a top level directory.
     
    Cybernaut, Mar 7, 2008 IP
  5. cyphix

    cyphix Well-Known Member

    Messages:
    245
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    103
    #5
    Great - thanks a lot for the detailed post! :)
     
    cyphix, Mar 7, 2008 IP