The .htaccess file works at the Apache web server level and allows you to control access to the site without changing the Joomla code. With its help you can restrict access to the admin panel, block suspicious requests and protect confidential files. We have configured .htaccess for more than 150 Joomla sites and we know which rules actually work. Let us look at the main ones.
Basic Protection from Suspicious Requests
Many attacks exploit typical patterns in URLs. Blocking such requests cuts off a large part of automatic scanners:
- Requests with
base64_encodein the parameters. - Attempts to access
configuration.phpdirectly. - Requests to non-existent files in non-standard directories.
- Suspicious User-Agents typical of bots.
Each rule must be checked so as not to block legitimate traffic.
Protecting configuration.php
The configuration.php file contains database credentials — its leak is critical. Close direct access to it:
- Block HTTP requests to configuration.php.
- Leave access only for PHP scripts.
- Check that the file cannot be downloaded via a browser.
This is a basic measure worth applying on any Joomla site.
What to Protect in .htaccess
The main targets for the rules:
- The administrator folder — restriction by IP.
- The configuration.php file — a ban on direct access.
- The tmp folder — a ban on executing PHP.
- Suspicious requests — blocking by patterns.
Banning PHP Execution in Upload Folders
The images, tmp, cache folders should not execute PHP scripts. If an attacker uploads a web shell there, they will not be able to run it. The rule is simple:
- Disable PHP execution in these directories.
- Allow only the upload and delivery of static files.
- Check that images and uploads work correctly after the configuration.
Restricting Access to the Admin Panel by IP
If you have a static IP or a limited list of addresses, restrict access to the administrator folder:
- Create a
.htaccessinside the administrator folder. - Allow access only from your IPs.
- Block all other addresses.
Do not forget to update the rules when your IP address changes.
Caution When Editing
A wrong rule in .htaccess can bring down the site:
- Make a backup of the file before changes.
- Check the site after each change.
- Do not copy rules without understanding what they do.
- Test on a test domain if possible.
If you are not sure — it is better to contact a specialist than to break a working site.
".htaccess is a tool that requires care. One wrong rule can cost the site its operability."
If you want to configure protection via .htaccess but are not sure about the rules — we have a Joomla Security and Firewall service: we close typical vulnerabilities, configure the WAF and admin panel protection in 2–3 days, with a 30-day guarantee. And before the configuration we recommend a Technical Joomla Audit — it will show what is already working well and what requires attention.