
Introduction
If you're hosting a simple static HTML website, you’ve probably noticed this issue:
- ✅
/services.html
— works perfectly - ❌
/services
— gives a 404 error
This is because the server expects exact filenames unless told otherwise. In this blog post, I’ll show you how to fix that and get clean URLs (like /about
) working on static HTML sites using a small tweak to your .htaccess
file.
Why Does This Happen?
When you visit a URL like /about
, the server looks for a folder named about/
and tries to load about/index.html
. But in most static websites, you just have a file called about.html
— not a folder. So, the server can’t find it and returns a 404.
✅ Solution: Use .htaccess to Rewrite URLs
If you're using Hostinger or any hosting that supports Apache (or LiteSpeed), you can add the following rule in your .htaccess
file inside public_html
:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.*)$ $1.html [L]
🔍 What This Does
! -d
→ Only rewrite if the path is NOT a directory%{REQUEST_FILENAME}.html -f
→ Checks if a matching.html
file existsRewriteRule
→ Rewrites the URL behind the scenes to load the correct file
✅ Result
Now, you can access the following clean URLs:
/services
→ servesservices.html
/about
→ servesabout.html
/contact
→ servescontact.html
All without needing to manually type .html
in the browser — a small change, but a big win for user experience and aesthetics.
💡 Bonus Tip: This Works on Hostinger Too
If you're using Hostinger (like I am), it uses LiteSpeed — a high-performance, Apache-compatible server. So, all .htaccess
rules work the same way as on Apache.
Conclusion
Static HTML sites don’t offer routing by default, but a simple `.htaccess` rule can make your URLs cleaner and more professional.
If you’ve been frustrated by broken links like /services
not working — now you know why, and exactly how to fix it.
💬 Have you faced this issue? Try the fix and let me know how it goes!
👨💻 Follow me on LinkedIn for more frontend and deployment tips.