Search code examples
.htaccessmod-rewrite

Basic .htaccess %{REQUEST_URI} not working


A WordPress site is being hammered by bots from a number of IP addresses. The URL is https://example.com/product/something/#comment-1804 but there is no such comment. I am not even sure why someone is doing this apart from a DOS attempt, but it is a pretty low level site that doesn't have many visitors.

I am trying to force anyone coming to that URL to a 403 page with this to reduce resource and bandwidth usage.

RewriteEngine On
RewriteCond %{REQUEST_URI} comment-1804
RewriteRule ^ - [F] [END]
</IfModule>

...and the WordPress rules.

But simple as it is, it isn't working. If I create an error e.g. %{REQUEST_URI}comment-1804 it breaks the site i.e. the rewrite condition is being read.

What is the problem?


Solution

  • I discovered that this will never work. The fragment of the URL following a # isn't processed in .htaccess

    Perhaps this is a trick being used by bots to avoid being blocked in .htaccess.