Using .htaccess on HostGator to Block Unwanted IP Addresses
An .htaccess file gives you a practical way to control access to an Apache-powered website without changing server-wide settings. On a HostGator shared hosting plan, it can deny requests from a particular IPv4 address, an IPv6 address, or a defined range before visitors reach protected pages.
This is useful when your access logs show repeated login attempts, comment spam, scraping, aggressive bots, or suspicious requests from a known address. It is a targeted measure rather than a complete security system, since an attacker can change networks, use a VPN, or rotate through many addresses.
Australian site owners often manage these issues on modest business websites, community projects, online shops, and personal blogs hosted from Sydney, Melbourne, Brisbane, Perth, or regional areas. Before blocking anyone, check the evidence carefully: Australian homes frequently use dynamic NBN addresses, while mobile networks may place many customers behind carrier-grade NAT.
Locate .htaccess in HostGator cPanel
Log in to HostGator cPanel and open File Manager. Select the website’s document root, which is commonly public_html for the primary domain. Add a check beside Show Hidden Files (dotfiles) in the settings window, because files beginning with a full stop are hidden by default.
Look for a file named .htaccess. If it does not exist, create a new file with precisely that name. Do not accidentally create .htaccess.txt, as Apache will ignore the latter. If you manage an addon domain, its document root may be a separate folder, so verify the correct path in cPanel’s Domains area before editing anything.
Download a backup copy before changing the file. A small syntax error can produce a 500 Internal Server Error, making the website unavailable until the mistake is removed. Keep the current contents in a text editor, then add new rules at the beginning or end without deleting existing WordPress, caching, redirects, or SSL directives.
Set ordinary file permissions, usually 644, and avoid changing ownership from cPanel. You can also use an FTP client, but File Manager is often simpler for a first-time change. HostGator’s security guide can sit alongside the account tools, tutorials, and support resources you use while checking the setup.
Add an IP deny rule safely
For servers using Apache 2.4 syntax, a simple rule that blocks one IPv4 address is:
<RequireAll>
Require all granted
Require not ip 203.0.113.45
</RequireAll>
Replace 203.0.113.45 with the address you intend to deny. The documentation example uses a reserved address range, so substitute a real address from your own access logs. To block several addresses, place each one on its own line:
<RequireAll>
Require all granted
Require not ip 203.0.113.45
Require not ip 198.51.100.27
</RequireAll>
A complete block will normally return HTTP status 403 Forbidden. That tells a browser or automated client that the server understood the request but will not allow access. It is different from a redirect, which sends the visitor somewhere else and still permits the request to reach the web server.
Some older Apache configurations use the legacy syntax below:
Order Allow,Deny
Allow from all
Deny from 203.0.113.45
Do not place both styles together unless HostGator support confirms that the required compatibility module is enabled. Shared hosting environments can vary by server and account configuration. If the modern rule causes a 500 response, restore the backup immediately and check the active Apache version or ask HostGator support which access-control syntax applies to your plan.
You can block an address range by using a network prefix, although broad ranges require caution. A rule such as Require not ip 203.0.113.0/24 denies the entire range from .0 through .255. This may catch neighbouring customers, a school, office, or legitimate crawler, so a single-address rule is safer when the evidence supports it.
Choose the right blocking method
An IP deny rule is best for a narrow, known problem. It can stop a persistent brute-force source, a faulty monitoring service, or a scraper that ignores robots.txt. It does not identify a person with certainty, and IP addresses are not reliable personal identifiers. In Australia, privacy obligations under the Privacy Act 1988 and the Australian Privacy Principles may affect how you collect, retain, and disclose log data, particularly for organisations covered by the legislation.
HostGator cPanel may also include IP Blocker or IP Deny Manager, depending on the account interface. That tool writes an access rule for you and may be preferable when you do not want to edit configuration manually. A web application firewall, WordPress security plugin, rate limiter, or CDN can be more suitable when attacks come from hundreds of addresses.
| Method | Best use | Main limitation |
|---|---|---|
.htaccess rule |
A small list of confirmed addresses | Manual maintenance and possible syntax errors |
| cPanel IP blocker | Straightforward single-address or range blocks | The feature may differ between HostGator plans |
| WordPress security plugin | Login abuse and application-level threats | Requires updates and consumes site resources |
| CDN or web application firewall | Distributed attacks and automated filtering | Needs separate configuration and may affect DNS |
| Hosting support ticket | Unclear server behaviour or persistent abuse | Response time depends on the issue and plan |
Consider where the blocking should happen. An .htaccess rule acts at the Apache website level, while a firewall can filter traffic earlier. If the same source attacks several domains on your account, a hosting-level solution is more efficient than copying rules into every website. The HostGator knowledge base, ticket system, and customer forums can help clarify which controls are available on a particular package.
Avoid blocking legitimate Australian visitors
Australian internet connections change frequently. An NBN customer in Adelaide may receive a different address after a modem reconnect, and a traveller using Telstra, Optus, or Vodafone mobile data may appear behind a shared address. Blocking one mobile IP can therefore affect many unrelated visitors. The same issue applies to public Wi-Fi at a library, airport, university, or café.
Check the timestamp, requested URL, user agent, response status, and request frequency before adding a rule. Compare several log entries rather than acting on one failed login. A burst of requests to /wp-login.php from one address is stronger evidence than a single visit to a public page. If a reverse proxy or CDN is in use, make sure your logs show the real client address; otherwise, you may block the proxy itself and take down the whole site.
IPv6 requires a different format. An IPv6 address can be added to the modern directive like this:
<RequireAll>
Require all granted
Require not ip 2001:db8:1234::25
</RequireAll>
Use the exact address or a carefully verified prefix. Do not assume that blocking an IPv4 address also blocks the same visitor over IPv6. A visitor may also switch from home broadband to a phone hotspot, so access control should be paired with stronger login protections and sensible rate limits.
If a site publishes gaming-related material, such as casino demo games, monitor abuse around forms, registrations, and promotional pages separately. Security logs should be retained only as long as needed for a legitimate purpose, with access limited to people responsible for operating the website.
Test, monitor, and remove old rules
After saving .htaccess, visit the website from an allowed connection and confirm that normal pages, images, forms, HTTPS redirects, and admin functions still work. Then test the blocked address from a suitable network or use a trusted testing service. A 403 response confirms that the rule is being applied, although a browser may display a custom error page rather than a plain server message.
If the site returns a 500 error, rename the edited file temporarily or restore the backup through File Manager. Common causes include a missing closing tag, a misspelled directive, unsupported Apache syntax, or rules copied into the wrong domain folder. Make one change at a time so you can identify which line caused the failure.
Review access logs after several hours and again after a few days. A blocked source may disappear, while a new address may begin the same behaviour. Keep a short record of the address, reason, date added, and date reviewed. Remove obsolete entries instead of allowing a long list to grow indefinitely.
Account security should cover more than public web traffic. Enable two-factor authentication for the HostGator account and review HostGator 2FA steps before relying on IP restrictions. A compromised cPanel password can bypass the value of carefully maintained website rules.
A practical maintenance routine
Start with the narrowest rule that solves the documented problem: one address rather than an entire provider or country. Save a backup, add the directive in the correct document root, and test both blocked and permitted access. If the rule affects legitimate users, remove it and investigate the application, login form, or upstream firewall instead of expanding the block.
For Australian businesses, align the process with normal privacy and record-keeping practices. Limit access to raw logs, avoid publishing personal details connected to an address, and retain security evidence for a defensible operational period. A local customer in Melbourne or a remote worker in regional Queensland should not lose access simply because a shared carrier address appeared in an automated abuse report.
The most reliable arrangement combines .htaccess for a small number of verified IPs, strong passwords and two-factor authentication for account access, software updates, and monitoring that reveals changing attack patterns. Treat each deny rule as a documented, reversible control rather than a permanent answer.
The practical takeaway is simple: back up .htaccess, block only confirmed addresses with the syntax supported by your HostGator server, test immediately, and review every rule as network conditions change.