Ahmad Alfy
Ahmad Alfy

Reputation: 13381

Using .htaccess to block URL containing a keyword only if it is not containing another keyword

This is an odd situation, someone is hammering our servers with http requests trying to access different TinyMCE based editors. I want to block any URL containing the keyword editor but we have valid working URLs containing the same word ... For example letter-from-editor.html or editorial-board.html

Is there a way using .htaccess I can contain any URL containing the keyword editor only if it doesn't contain the keyword html ?

This is what I am trying right now that blocks editor only

RewriteRule (^|/)editor(/|$) - [F,L]

I really searched and I couldn't find a way around it. Thanks

Upvotes: 0

Views: 1555

Answers (2)

Croises
Croises

Reputation: 18671

With that, you block only link that do not exist:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (^|/)editor(/|$) - [F,L]

Upvotes: 1

rekire
rekire

Reputation: 47985

You need to add a simple condition:

RewriteCond %{REQUEST_URI} !html
RewriteRule (^|/)editor(/|$) - [F,L]

Upvotes: 3

Related Questions