Report this

What is the reason for this report?

How to block - Libwww-perl Access in .htaccess?

Posted on May 25, 2015

Hi there,

I’m not sure how to block -Libwww-perl using .htaccess. When I add this code after “RewriteEngine on” line:

RewriteCond %{HTTP_USER_AGENT} libwww-perl.* RewriteRule .* – [F,L]

I get a 500 internal error (even though I restart Apache2)

Thank you!



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

RewriteCond %{HTTP_USER_AGENT} libwww-perl.* RewriteRule .* - [F,L]

Modify as per above

Check your error log to find out why.

Heya,

The .htaccess rules look okay, but you can check a few things. Make sure there are no leading or trailing spaces or line breaks in the file that could cause syntax errors. Your code should be formatted correctly like this:

  1. RewriteEngine on
  2. RewriteCond %{HTTP_USER_AGENT} libwww-perl.* [NC]
  3. RewriteRule .* - [F,L]

*. Mod_rewrite Module: Ensure that the mod_rewrite module is enabled in your Apache configuration. You can enable it using the following command:

  1. sudo a2enmod rewrite

After enabling mod_rewrite, make sure to restart Apache for the changes to take effect:

  1. sudo systemctl restart apache2
  • Check for Other .htaccess Rules: If you have other rules in your .htaccess file, they might be conflicting with the provided code. Make sure there are no conflicting rules.

  • Error Logs: Check your Apache error logs for more detailed information about the 500 internal error. The logs can usually be found in the /var/log/apache2/error.log file on Linux servers. Look for any specific error messages related to the .htaccess file or the mod_rewrite module.

  • Permissions: Ensure that the .htaccess file has the correct permissions. It should be readable by the Apache web server. You can set the permissions using the chmod command if necessary:

  1. chmod 644 .htaccess
  1. Apache Configuration: Make sure that the Apache configuration allows the use of .htaccess files. In your Apache configuration file (usually located at /etc/apache2/apache2.conf or /etc/httpd/httpd.conf), you should have a section that looks like this:
  1. <Directory /var/www/html>
  2. Options Indexes FollowSymLinks
  3. AllowOverride All
  4. Require all granted
  5. </Directory>

The AllowOverride All directive is essential to allow .htaccess files to override the server configuration. After making changes to your Apache configuration, don’t forget to restart Apache.

After going through these troubleshooting steps, you should be able to determine the cause of the 500 internal error and resolve it. If you still encounter issues, please provide any relevant error messages from your Apache logs for further assistance.

Hope that this helps!

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.