使用正则表达式阻止.htaccess中的URL

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:

  • mp4:
  • wp-content
  • phpMyAdmin

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

How can I accomplish this?

Thanks!

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! :)

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.