How to protect an /admin path on a small website
Typing /admin after a domain name is one of the first things automated scanners try. If that path exists on your site, it needs a real lock, not just an unusual name.
Why obscurity is not security
Renaming /admin to /office-7k2 stops some lazy bots, but the secret address leaks in many ways: browser history, shared screenshots, a link in a public repository, a line in robots.txt, or a JavaScript file that mentions it. Once found, the page is as open as before. Treat a hidden address as noise reduction, and add at least one of the controls below.
First question: does the page need to exist?
Static sites are often generated from a builder or a template that ships sample admin, login or dashboard pages. If nothing on your site needs them, delete them. A page that does not exist cannot be attacked. Then make the old address return 404, or redirect it to a public page, and remove it from your sitemap.
Also check for leftovers: setup scripts, database tools, backup files such as site.zip in the web root, and .git folders. Each one can expose more than an admin page.
Option A: HTTP basic authentication
Most web servers can ask for a username and password before serving a folder. The browser shows a simple login prompt and the server checks the credentials against a password file. On Apache this is done with an .htaccess file in the folder:
AuthType Basic
AuthName "Restricted"
AuthUserFile /home/site/.htpasswd
Require valid-user
Create the password file with the htpasswd tool and keep it outside the public web folder. Nginx and most managed hosts offer the same feature under a different setting name. Basic auth only protects the password in transit when the whole site runs over HTTPS.
Option B: an IP allow-list
If admins always work from a known office network or VPN, let only those addresses reach the path. On Apache:
<Location "/admin">
Require ip 203.0.113.10
</Location>
The address above comes from a range reserved for documentation; use your own. Home connections often change address, so allow-lists suit fixed networks or a VPN better than individual laptops.
Option C: move the admin off the public site
Many modern setups keep editing completely separate: content is edited in a local tool or a hosted editor, and the public site is only static files. There is no admin path on the live domain at all.
Comparing the options
| Option | Effort | Strength |
|---|---|---|
| Rename the path | Low | Weak on its own |
| Delete unused admin pages | Low | Strong, for pages you do not need |
| Basic auth over HTTPS | Low to medium | Good extra layer in front of an app login |
| IP allow-list or VPN | Medium | Strong when networks are stable |
| Separate editing system | Higher | Strong; nothing to attack on the live site |
Mistakes
- Listing the admin path in
robots.txt, which publishes it. - Protecting
/admin/but not/admin/index.phpor an API the admin screens call. - Using a client-side JavaScript password check. Anyone can read the script.
Questions
Is a password prompt enough on its own?
Stack layers where you can: a strong unique password, two-factor login in the application, and a network restriction in front.
How do I test the protection?
Open the path in a private window from a different network, such as a phone on mobile data. You should see a prompt or a block, never the admin screen.