Guillermo
Guillermo

Reputation: 864

Block URLs in .htaccess using regular expression

I would like to block a couple of URLs if they match a regular expression in the htaccess file.

These are the URLs I want to block in htaccess.

Anything that contains the following in the URL pattern:

All case insensitive, please note that the "mp4:" must include the colon to match the expression.

How can I accomplish this?

Thanks!

Upvotes: 2

Views: 4317

Answers (2)

marcanuy
marcanuy

Reputation: 23942

This should work:

RewriteEngine On
RewriteCond %{THE_REQUEST} ^.*(wp-content)|(phpMyAdmin)|(mp4:).* [NC]
RewriteRule ^(.*)$ - [F,L]

Then a Forbidden message will be displayed for urls containing such string. e.g.:

You don't have permission to access /foomp4:bar/ on this server.

Upvotes: 5

Eric Bruggema
Eric Bruggema

Reputation: 17

I hope this is what you are looking for, example

RedirectMatch users/(.+) http://www.exapmles.com/profiles/$1 [R=301,L]

more information can be found here https://superuser.com/questions/155139/htaccess-301-redirect-with-regular-expressions

In your case you should add multiple lines! :)

Upvotes: 0

Related Questions