Reputation: 21
I have a Drupal
site where new content is added very rarely. Recently, there have been an increasing number of visits from bots to various URLs (node/add, user/register), which return Drupal's
"Access denied" page.
I want to block access to these URLs in .htaccess
. I have tried the following and it works:
<IfModule mod_alias.c>
Redirect 403 /node/add
Redirect 403 /user/register
</IfModule>
However, bots can still access ?q=node/add and ?q=user/register
. I have tried including ?q=
in the code above but no success.
How do I block access to these URLs in .htaccess
?
Upvotes: 1
Views: 2317
Reputation: 609
While doing this via .htaccess is completely viable, I would reconsider this approach and consider putting these URLs into robots.txt for crawler bots. This way, they will ignore them completely, which is definitely more healthy for SEO.
Also, you can use Global Redirect module (https://drupal.org/project/globalredirect) to ensure that only clean URLs are used.
Upvotes: 2
Reputation: 20737
You can use mod_rewrite
to do url-manipulation based on the query string. You'll need something like the (untested) code below.
RewriteEngine On
RewriteCond %{QUERY_STRING} ^q=(node/add|user/register)$
RewriteRule ^ - [F,L]
What does this do? It matches any url (^
), then checks if the query string is equal to q=node/add
or q=user/register
. If either one matches, then the url is not rewritten (-
), but access is denied [F]
and the rewriting stops for this iteration [L]
.
Upvotes: 4