Web Hosting Q&As Logo
Web Hosting Q&As Part of the Q&A Network
Q&A Logo

How do I block an IP address using .htaccess?

Asked on Sep 15, 2025

Answer

To block an IP address using .htaccess, you can use the "deny from" directive within the file. This will prevent the specified IP address from accessing your website.

    Order Allow,Deny
    Deny from 192.168.1.1
    Allow from all
    
Additional Comment:
  • Place the .htaccess file in the root directory of your website.
  • Replace "192.168.1.1" with the IP address you wish to block.
  • Ensure your server is configured to use .htaccess files (common in Apache setups).
  • Use caution when editing .htaccess, as incorrect syntax can cause server errors.
✅ Answered with Web Hosting best practices.

← Back to All Questions
The Q&A Network