jona303
jona303

Reputation: 1568

Regex do not start with string or do not end with string

i'm lost in a regular expression issue.

I need to make a pattern in a htaccess file to match path that doesn't start with

view or doesn't end with (.oet|.ttf,..)

I can make the part for view, but not the end part.

to test view I have :

^(?!view)(.*)$

I tried to test to not end with .eot like this but it doesn't work :

^(.*)(?!.oet)$

the final test i would like should look like this :

^((?!view)(.\*))|((.\*)(?!.eot|.ttf|.otf|.woff))$

can someone help me please ?

Upvotes: 1

Views: 436

Answers (2)

anubhava
anubhava

Reputation: 785376

mod_rewrite gives you flexibility of breaking it into 2 separate matches using `RewriteCond which will be much more maintainable than one single complex regex.

You can use it like this:

RewriteCond %{REQUEST_URI} !\.(eot|ttf|otf|woff)$ [NC]
RewriteRule ^((?!view).*)$ /view/$1 [L,NC]

Upvotes: 3

aelor
aelor

Reputation: 11116

you need a negative lookbehind.

^(?!view).*?(?<!.eot|.ttf|.otf|.woff)$

demo here : http://regex101.com/r/dP3gS3/2

Upvotes: 0

Related Questions