skip to Main Content

I am trying to write a regular expression for apache virtual host configuration that will map request if URI doesn’t have certain extensions. Below expression I have written.

^/bookdata/.+.(?!jpg|mp3|mp4|zip|doc|pdf|xls|xlsx).*$

Below URI is not matching to this expression which is perfectly fine.

/bookdata/rw0/media/Q2e_00_RW_U08_Q_Classroom.mp3?fd=1

My problem with below URI which is matching with this expression due to two dots.

/bookdata/rw0/media/ELM2_U02_Track06_Chart2.8.mp3?fd=1

Any small help will be appreciated.

2

Answers


  1. Put the neg. lookahead right at the start, like so

    ^(?!.*.(?:jpg|mp3|mp4|zip|doc|pdf|xls|xlsx))/bookdata/.+$
    

    See a demo on regex101.com.

    Login or Signup to reply.
  2. As I know request URI doesn’t contain request params(after question mark)
    So you can ommit .* at the end of your regex then you can match your prefer uris.
    This happen because you say that your uri end by those extension must not match.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search